java一串String类型的字符串split以切割之后用stream流转为int类型然后收集成list
可以使用以下代码实现:
String str = "1,2,3,4,5";
List<Integer> list = Arrays.stream(str.split(","))
.map(Integer::valueOf)
.collect(Collectors.toList());
首先,使用split函数将字符串按照逗号分割成字符串数组。然后使用Stream的map函数将每个字符串转换为整数类型,最后使用collect函数将结果收集到List中。
原文地址: https://www.cveoy.top/t/topic/gg85 著作权归作者所有。请勿转载和采集!