Array to Collection: Optimized code

前端 未结 10 2027
萌比男神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 14:48

    What about :

    List myList = new ArrayList(); 
    String[] myStringArray = new String[] {"Java", "is", "Cool"}; 
    
    Collections.addAll(myList, myStringArray); 
    

提交回复
热议问题