需求:
现在有一个List<Integer>
集合,需要把它转换成List<Long>
集合。
声明:不想使用循环
实现方式
使用com.alibaba.fastjson
包下的 JSONArray
类实现
代码示例
public static void main(String[] args) {
List<Integer> listInt = new ArrayList<>();
listInt.add(1);
listInt.add(2);
listInt.add(3);
List<Long> listLong = JSONArray.parseArray(listInt.toString(),Long.class);
System.out.println(listLong);
}
同理,使用该方式List<Long>
转List<Integer>
也是OK的。
如果该文章有帮助到您,就留言点个赞吧!您的支持与肯定是我持续更新最大的动力。