Initialization of an ArrayList in one line

后端 未结 30 2630
北恋
北恋 2020-11-22 01:10

I wanted to create a list of options for testing purposes. At first, I did this:

ArrayList places = new ArrayList();
places.add(\         


        
30条回答
  •  醉梦人生
    2020-11-22 01:43

    You can use the below statements:

    Code Snippet:

    String [] arr = {"Sharlock", "Homes", "Watson"};
    
    List names = Arrays.asList(arr);
    

提交回复
热议问题