sarah
sarah

Reputation: 2397

List index value retrieval

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 ?

Upvotes: 4

Views: 43696

Answers (2)

Bozho
Bozho

Reputation: 597124

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.

Upvotes: 23

Adam Luchjenbroers
Adam Luchjenbroers

Reputation: 5019

I'd go with get().

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

Upvotes: 1

Related Questions