Let’s say I have an array list of objects, and each object has the Parameters:
Object(String string, int x, int y)
How would I get only the string parameter at the given index? I hope I’m not being too broad here..
I only want to retrieve the String parameter from the Object at the specified index in my ArrayList.
Use generic ArrayLists if at all possible and simply call your object’s getter method for the field whose value you wish to obtain. Otherwise if you can’t use a generic ArrayList, you’ll have to cast the object returned to the type it should be before calling the getter (accessor) method.
e.g. assuming a getter method of
getString(),if not generic you’ll have to cast to your object’s class: