转换列表<串GT;列出<整数GT;直 [英] Convert List<String> to List<Integer> directly

查看:100
本文介绍了转换列表<串GT;列出<整数GT;直的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解析我的文件S包含后 AttributeGet:1,16,10106,10111

所以我需要在attributeIDGet列表分号后能得到所有的数字。我知道有几个方法可以做到这一点。但有什么办法,我们可以通过直接将列表<弦乐> 列表<整数方式>
由于低于code抱怨类型不匹配,所以我试图做的Integer.parseInt,但我想这不会对列表工作。下面就为String。

 私有静态列表<整数GT; attributeIDGet =新的ArrayList<整数GT;();;如果(s.contains(AttributeGet:)){
    attributeIDGet = Arrays.asList(s.split(:)[1] .split(,));
}


解决方案

没有,你需要循环阵列上

 的(一个String:strList)intList.add(Integer.valueOf(S));

After parsing my file s contains AttributeGet:1,16,10106,10111

So I need to get all the numbers after semi colon in the attributeIDGet List. I know there are several ways to do it. But is there any way we can Directly convert List<String> to List<Integer>. As the below code complains about Type mismatch, so I tried to do the Integer.parseInt, but I guess this will not work for List. Here s is String.

private static List<Integer> attributeIDGet = new ArrayList<Integer>();;

if(s.contains("AttributeGet:")) {
    attributeIDGet = Arrays.asList(s.split(":")[1].split(","));
}

解决方案

No, you need to loop over the array

for(String s : strList) intList.add(Integer.valueOf(s));

这篇关于转换列表&LT;串GT;列出&LT;整数GT;直的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆