im having a bit of trouble using the object i add to my arraylist. i used this as my reference:
http://www.java2s.com/Tutorial/CSharp/0220__Data-Structure/ArrayListandyourownobjectAddobjectstoArrayList.htm
import java.util.ArrayList;
public class TestArrayList
{
public static void main(String[] args)
{
Object item1 = new ObjectMaker();
Object item2 = new ObjectMaker();
Object item3 = new ObjectMaker();
ArrayList<Object> arrayList = new ArrayList<Object>();
arrayList.add(item1);
arrayList.add(item2);
arrayList.add(item3);
System.out.println(arrayList);
//you made three objs item 1 2 3, added them to arrayList 0 1 2
//call method on each obj
for (int i = 0; i <= arrayList.size(); i++)
{
arrayList.get(i).info();
}
}
}
public class ObjectMaker
{
private static int count = 0;
String name;
int year;
ObjectMaker()
{
count++;
System.out.println("Making Object #" + count);
}
public void info()
{
System.out.println("You have used the obj in array list correctly");
}
}