1、List转换为String字符串,并且指定分隔符
ArrayList<String> keyList = new ArrayList<>();keyList.add("name");keyList.add("id");String keys = StringUtils.join(keyList.toArray(), " , ");System.out.println(keys);
运行结果如下
2、List转换为String字符串,并且指定分隔符,并且给字符串添加指定字符,比如添加单引号
ArrayList<String> keyList = new ArrayList<>();keyList.add("name");keyList.add("id");String values = keyList.stream().map(s -> "\'" + s + "\'").collect(Collectors.joining(", "));
运行结果如下