创build对象的Arraylist

如何用对象填充一个ArrayList,每个对象都不相同?

ArrayList<Matrices> list = new ArrayList<Matrices>(); list.add( new Matrices(1,1,10) ); list.add( new Matrices(1,2,20) ); 

如何创build对象的Arraylist。

创build一个数组来存储对象:

 ArrayList<MyObject> list = new ArrayList<MyObject>(); 

一步:

 list.add(new MyObject (1, 2, 3)); //Create a new object and adding it to list. 

要么

 MyObject myObject = new MyObject (1, 2, 3); //Create a new object. list.add(myObject); // Adding it to the list. 
Interesting Posts