java如何将数组转换为集合

走着路睡觉
  • java
小于 1 分钟

JDK

Element[] array = {new Element(1), new Element(2), new Element(3)};
//转换为集合
List<Element> list = Arrays.asList(array);
//换换为 ArrayList
new ArrayList<>(Arrays.asList(array));

Guava

List<String> l1 = Lists.newArrayList(anotherListOrCollection);    
List<String> l2 = Lists.newArrayList(aStringArray);              
List<String> l3 = Lists.newArrayList("or", "string", "elements");
上次编辑于:
贡献者: zhaojingbo
Loading...