Object
doesn't have a name
field. You could create your own class and then add an instance of that class to your collection.
You could do this:
public class CustomItem
{
private String name;
public CustomItem(String n)
{
this.name = n;
}
public String getName()
{
return this.name;
}
}
And add it to your arrayList
like this:
arrayList.add(new CustomItem("I1"));
If you wanted to check if a particular element of the collection matched some name, you would call the getName()
method on that element and compare it some name.