gpt4 book ai didi

java - 从 List 获取值

转载 作者:行者123 更新时间:2023-12-01 12:48:17 25 4
gpt4 key购买 nike

我对如何从 Object 获取值(value)感兴趣来自List<> 。这是对象的代码示例

@Override
public List<ListObject> initChildren() {

//Init the list
List<ListObject> mObjects = new ArrayList<ListObject>();

//Add an object to the list
StockObject s1 = new StockObject(this);
s1.code = "Системне програмування-1";
s1.num = "1.";
s1.value = "307/18";
s1.time = "8:30 - 10:05";
mObjects.add(s1);

StockObject s2 = new StockObject(this);
s2.code = "Комп'ютерна електроніка";
s2.num = "2.";
s2.value = "305/18";
s2.time = "10:25 - 11:00";
mObjects.add(s2);

StockObject s3 = new StockObject(this);
s3.code = "Психологія";
s3.num = "3.";
s3.value = "201/20";
s3.time = "11:20 - 13:55";
mObjects.add(s3);

StockObject s4 = new StockObject(this);
s4.code = "Проектування програмного забезпечення";
s4.num = "4.";
s4.value = "24";
s4.time = "14:15 - 16:50";
mObjects.add(s4);

return mObjects;
}

最佳答案

您可以使用 get() 方法,如下所示

mObjects.get(index)

其中索引是列表的从零开始的索引,就像数组一样。要直接访问对象,您可以这样做,

mObjects.get(index).code

关于java - 从 List<ListObject> 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com