i have MyClass as
MyClass(String, String, int);
i know about how to add to add to ArrayList in this way:
MyClass.name = "Name";
MyClass.address = "adress";adress
MyClass.age = age;
then add to arrayList like:
list.add(MyClass);
but now i have many object MyClass in static form, i want to add
ArrayList<MyClass> list = new ArrayList<MyClass>({"Name","Address", age};.....);
can i do like this. thank anyway
You can use double braces initialization: –
As you can see that,
inner bracesis just like aninitializerblock, which is used to initialize thelistin one go..Also note the semi-colon at the end of your
double-braces