> 文档中心 > String类型转换成List<Integer>

String类型转换成List<Integer>

@Test    void contextLoads() { String ids = "1,2,3,4,5,6"; String[] items = ids.split(","); List<Integer> appIdList = Stream.of(items).map(Integer::parseInt).collect(Collectors.toList()); System.out.println(appIdList);    }

String类型转换成List<Integer>

@Test    void test01(){ String s = "1"; String s1 = "1,2,3"; String s2 = "4,5,6"; new ArrayList<String>() {{     add(s);     add(s1);     add(s2); }}.stream().flatMap(e -> Stream.of(e.split(","))).collect(Collectors.toList()).forEach(System.out::println);    }

String类型转换成List<Integer>