Array to Collection: Optimized code

前端 未结 10 2158
萌比男神i
萌比男神i 2021-01-31 14:26

Is there a better way of achieving this?

public static List toList(String[] array) {

    List list = new ArrayList(array.length);

          


        
10条回答
  •  没有蜡笔的小新
    2021-01-31 15:03

    Arrays.asList(array);    
    

    Example:

     List stooges = Arrays.asList("Larry", "Moe", "Curly");
    

    See Arrays.asList class documentation.

提交回复
热议问题