Get specific ArrayList item

KJW picture KJW · Oct 13, 2010 · Viewed 598.4k times · Source
public static ArrayList mainList = someList;

How can I get a specific item from this ArrayList? mainList[3]?

Answer

Tomas Narros picture Tomas Narros · Oct 13, 2010

As many have already told you:

mainList.get(3);

Be sure to check the ArrayList Javadoc.

Also, be careful with the arrays indices: in Java, the first element is at index 0. So if you are trying to get the third element, your solution would be mainList.get(2);