Java中String转List<Integer>

Java中String转List<Integer>

// 输入:“1,2,3”
String str  = "1,2,3"
List<String> isStr =Arrays.asList(str.split(","));
List<Integer> isInt = new ArrayList<>();
CollectionUtils.collect(isStr, new Transformer() {
     @Override
     public Object transform(Object obj) {
        return Integer.valueOf(obj.toString());
     }},isInt);
        
  System.out.println("isInt ====" +isInt);
// 输出代码:
isInt ==== [1,2,3]

Java中List<String>转String

// 输入:[1, 2, 3]
List<String> strList = [1, 2, 3];
String str = String.join(",",strList );

System.out.println("str===="  +str);
//输出:
str====  1,2,3
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页