获取特定的 ArrayList 项 [英] Get specific ArrayList item

查看:22
本文介绍了获取特定的 ArrayList 项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static ArrayList mainList = someList;

我怎样才能从这个 ArrayList 中得到一个特定的项目?mainList[3]?

How can I get a specific item from this ArrayList? mainList[3]?

推荐答案

很多人已经告诉过你:

mainList.get(3);

请务必查看ArrayList Javadoc.

另外,注意数组索引:在 Java 中,第一个元素位于索引 0.因此,如果您尝试获取第三个元素,您的解决方案将是 mainList.get(2);

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

这篇关于获取特定的 ArrayList 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆