转换列表<串GT;列出<整数GT;直

编程入门 行业动态 更新时间:2024-10-28 08:19:40
本文介绍了转换列表<串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;直

本文发布于:2023-11-26 22:49:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   列表   LT   GT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!