可以使用Java 8中的stream API来实现Collection转换为List

Collection<Long> collection = new ArrayList<>();
// 添加元素到集合中

List<Long> list = collection.stream().collect(Collectors.toList());

或者使用List接口的构造函数,将Collection作为参数传递:

Collection<Long> collection = new ArrayList<>();
// 添加元素到集合中

List<Long> list = new ArrayList<>(collection);
java中CollectionLong转换为 ListLong

原文地址: https://www.cveoy.top/t/topic/YtK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录