Java 将字符串用逗号分割并转换为 Integer 列表
可以使用如下代码实现:
String str = '1,2,3,4,5';
List<Integer> list = Arrays.stream(str.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
首先将字符串按照逗号分割成字符串数组,然后使用stream流将每个字符串转为Integer类型,并收集成一个List
原文地址: https://www.cveoy.top/t/topic/ouEs 著作权归作者所有。请勿转载和采集!