Java 列表索引值检索
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1974063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List index value retrieval
提问by sarah
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 ?
我有包含 a、b、c、d、e、f、g、h 等数据的列表,如果我想要这个列表,我会说 getList();它返回一个数组列表,我只需要索引 10 处的值,即 'i',我该怎么做?
采纳答案by Bozho
getList().get(8);
Have in mind that index is 0-based. So index 8
means the 9th
item.
请记住,索引是基于 0 的。所以索引8
意味着9th
项目。
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.
建议:始终查看javadoc,或打开 IDE 的自动完成功能,看看您的对象有哪些方法。它们中的大多数都以明确知道它们实际做什么的方式命名和记录。
For example, in your case, google for "ArrayList", open the first result (from java.sun.com), and look through the methods there.
例如,在您的情况下,谷歌搜索“ArrayList”,打开第一个结果(来自 java.sun.com),并查看那里的方法。