Insert and Retrieve Values from a List (ArrayList)

List list = new ArrayList();

//Adding values to the ArrayList
list.add(“test1”);
list.add(“test2”);
list.add(“test3”);

/**
*Retrieving values from list
*/
//—————————————
Iterator itr = list.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}

//—————————————
int size = list.size();
for(int i=0;i<size;i++)
{
System.out.println(list.get(i));
}

//—————————————
Enumeration e = Collections.enumeration(list);
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
}

this for POJO list retrievals
//—————————————
for(PojoList list1 : list){
System.out.println(list1.getColumnName());
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s