how to initialize static ArrayList in one line

后端 未结 6 421
醉话见心
醉话见心 2020-12-24 12:50

i have MyClass as

MyClass(String, String, int);

i know about how to add to add to ArrayList in this way:

MyClass.name = \"N         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-24 13:01

    You can do

    List list = Arrays.asList(
                             new MyClass("Name", "Address", age),
                             // many more
                         );
    

    Note: this will create a list where you can't change its size.

提交回复
热议问题