tags:

views:

83

answers:

2

Hi All,

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 ?

+8  A: 
getList().get(8);

Have in mind thet 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.

Bozho
+1. it should also be noted that index, here, is 0-based, and `i` is at index 8.
David Hedlund
In OPs list `i` is at the 9th position, that is `getList().get(8)` in Java, since Java starts counting with zero.
Adrian
thanks, I updated the answer with that clarification
Bozho
+1 for the javadoc and google refs
chburd
If you're using Eclipse, it actually has a separate Javadoc pane you can add to UI, you can find it from `Window -> Show View -> Java/Javadoc` It even reacts automatically to where your cursor is in source file which is incredibly handy.
Esko
A: 

I'd go with get().

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

Adam Luchjenbroers
Your link is pointing to the javadoc for the unreleased Java 7
Vincent Robert
Of course, one should bookmark the right version of the Java API docs (you link to Java 7 beta, which OP probably does not use)
Jonik
Thanks for pointing that out, fixed.
Adam Luchjenbroers