List转string 逗号分隔(转载)

转载来源:https://www.cnblogs.com/hmgx/p/11942342.html

1、将list转化为逗号分割的字符串

    String str = String.join(",", list);

    String str = StringUtils.json(list.toArray(), ",");   

 

2、将逗号分隔的字符串转换为List

    List<String> list = Arrays.asList(str.split(","));

    List<String> list = Arrays.asList(StringUtils.split(str, ","));

3、将字符串中的字符替换

    String newStr = str.replace("需替换的字符", "目标字符");

 

 

posted @ 2022-01-21 11:32  hao_1234_1234  阅读(13506)  评论(0编辑  收藏  举报