java中String字符串转化成list<Integer>格式

最近开发中遇到问题,同事在传给我ids时拼接为String字符串格式,转化成List,网上的转化大致为:

String[] strs = {"1","3","12","33"};
List<String> sList = Arrays.asList(strs); 

而我要的是转化后为List<Integer>格式,网上的资料也很难找到关于直接转化为我需要格式的例子,最终还是圆满的解决了个人的需求,直接上代码:

List<String> idsStringList = Arrays.asList(ids.split(","));
List<Integer> idsList = new ArrayList<>();
CollectionUtils.collect(idsStringList, new Transformer() {
   @Override
   public Object transform(Object o) {
	  return Integer.valueOf(o.toString());
   }
}, idsList);
ids="1,2,33,45,67"



猜你喜欢

转载自blog.csdn.net/zouxucong/article/details/79126793