Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List index value retrieval

Tags:

java

I have list having data like a, b, c, d, e, f, g, h, i if i want this list i would say getList(); which returns me a arraylist,i need only the value at index 10 that is 'i' ,how would i do this ?

like image 905
sarah Avatar asked Nov 28 '22 11:11

sarah


2 Answers

I'd go with get().

BTW, you can find the complete Java API docs here. I'd highly recommend bookmarking it.

like image 20
Adam Luchjenbroers Avatar answered Dec 05 '22 10:12

Adam Luchjenbroers


getList().get(8);

Have in mind that index is 0-based. So index 8 means the 9th item.

Advice: always look at the javadoc, or open the autocomplete of your IDE, to see what methods does your object have. Most of them are named and documented in a way that it is explicitly known what they actually do.

For example, in your case, google for "ArrayList", open the first result (from java.sun.com), and look through the methods there.

like image 62
Bozho Avatar answered Dec 05 '22 09:12

Bozho