JAVA字符串逗号分隔并对每个字符串添加引号
需求数据库IN查询时,括号内的字符串需要用””包起来实现```Stringstr=“the,quick,brown,,,,,fox,jumped,,,over,the,lazy,dog”;/
需求
数据库IN查询时,括号内的字符串需要用””包起来
实现
String str = "the,quick,brown,,,,,fox,jumped,,,over,the,lazy,dog";
//split the string
List<String> list = Arrays.asList(str.split(",", -1));
// add double quotes around each list item and collect it as a comma separated string
// 核心就是在这一块
String strout = list.stream().collect(Collectors.joining("\",\"", "\"", "\""));
//replace two consecutive double quotes with a empty string
strout = strout.replaceAll("\"\"", "");
System.out.println(strout);
相关文章
- okhttp、okhttp3使用post方式发送form-data数据
- [Docker系列] Install BaoTa with Docker
- [信创系列]银河麒麟安装nodejs18和npm2,并启动对应工程
- EasyExcel导出Excel并合并单元格
- Python3安装pip及pip安装whl包
- [Ubuntu系列]Ubuntu 安装 Harbor
- [Ubuntu系列]Ubuntu 安装 docker 及修改 docker 存储位置
- [Centos系列]CentOS 修改 DNS
- [Centos系列]source /etc/profile 无法永久生效问题
- Linux系统根据CPU架构确定安装包
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~