java - Get specific ArrayList item

ID : 20152

viewed : 28

Tags : javaarraylistjava

Top 5 Answer for java - Get specific ArrayList item

vote vote

98

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);

vote vote

83

Time to familiarize yourself with the ArrayList API and more:

ArrayList at Java 6 API Documentation

For your immediate question:

mainList.get(3);

vote vote

75

mainList.get(list_index) 
vote vote

62

mainList.get(3); 

For future reference, you should refer to the Java API for these types of questions:

http://download.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html

It's a useful thing!

vote vote

56

We print the value using mainList.get(index) where index starts with '0'. For Example: mainList.get(2) prints the 3rd element in the list.

Top 3 video Explaining java - Get specific ArrayList item

Related QUESTION?