解析我的文件“s”后包含AttributeGet:1,16,10106,10111
所以我需要获取attributeIDGet List中冒号后的所有数字。我知道有几种方法可以做到这一点。但是有什么方法可以直接转换List<String>
至List<Integer>
.
由于下面的代码提示类型不匹配,所以我尝试执行 Integer.parseInt,但我想这不适用于 List。这里 s 是字符串。
private static List<Integer> attributeIDGet = new ArrayList<Integer>();
if(s.contains("AttributeGet:")) {
attributeIDGet = Arrays.asList(s.split(":")[1].split(","));
}
最佳答案
使用 Java8:
stringList.stream().map(Integer::parseInt).collect(Collectors.toList());
关于java - 将 List<String> 直接转换为 List<Integer>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706721/