如何检索存储在Java ArrayList中的对象值 [英] How to retrieve objects values stored in a Java ArrayList

查看:97
本文介绍了如何检索存储在Java ArrayList中的对象值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ArrayList<yellowPage> ob1 = new ArrayList<yellowPage>(); 
yellowPage thing = new yellowPage(100,100);
thing.calc(i,y,s3); 
ob1.add(thing);

我将一些数据存储在的东西中。如何检索存储在 ob1.thing 中的值?

I stored some data in thing. How can I retrieve the value stored in ob1.thing?

推荐答案

如果您知道索引,则可以执行yellowPage

If you know the index, you can do yellowPage

yellowPage yp = ob1.get(index);

否则你需要遍历列表。

Iterator<yellowPate> iter = ob1.iterator();
while(iter.hasNext())
{
    yellowPage yp = iter.next();
    yp.whateverYouwantGet();
}

注意:我这里只输入代码,可能存在语法错误。

Note: I just typed code here, there may be syntax errors.

这篇关于如何检索存储在Java ArrayList中的对象值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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