how to initialize static ArrayList in one line

后端 未结 6 429
醉话见心
醉话见心 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:15

    Something like this:

    List list = new ArrayList(Arrays.asList(new MyClass[] {new MyClass("Name", "Address", age}));
    

    Of course, your class must have a constructor like this:

    public MyClass(String name, String address, int age) {
    ...
    }
    

提交回复
热议问题