Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve objects values stored in a Java ArrayList

Tags:

java

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

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

like image 678
user768990 Avatar asked Feb 11 '12 06:02

user768990


1 Answers

If you know the index, you can do yellowPage

yellowPage yp = ob1.get(index);

Otherwise you need to iterate over the list.

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.

like image 183
kosa Avatar answered Oct 10 '22 12:10

kosa