Adding value to List<String> = new ArrayList<String>();

This question already has an answer here:

  • Initialization of an ArrayList in one line 32 answers

  • Try,

    ArrayList<String> list = new ArrayList<String>() {{
        add("item1");
        add("item2");
        add("item3");
    }}
    

    OR

    ArrayList<String> list = new ArrayList<String>();
    list.add("item1");
    list.add("item2");
    list.add("item3");
    

    这里是:

    List<String> sample = new ArrayList<String>(Arrays.asList("item1", "item2", "item3"));
    
    链接地址: http://www.djcxy.com/p/27714.html

    上一篇: 如何在java中创建链表?

    下一篇: 给List添加值<String> = new ArrayList <String>();