新的,在这里学习。所以假设我在这个列表中有多个PhoneCalls,我只想弄清楚最简单的访问方式如何让我们说第7个电话号码号码我该怎么办呢? .get()给了我所有的信息,但我只想要它的一部分。
class PhoneCall{
String name;
String number;
String type;
String date;
PhoneCall(String name, String number, String type, String date)
{
this.name = name;
this.number = number;
this.type = type;
this.date = date;
}
ArrayList<PhoneCall> list = new ArrayList<PhoneCall>();
list.add(new PhoneCall(name,number,type,date));
答案 0 :(得分:2)
使用get
方法:
list.get(index);
如果您不想要整个PhoneCall
对象,只能从对象中获取某个字段:
list.get(index).field;
所以,要回答你的问题,请执行:
list.get(6).number;