Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to iterate nested lists in java

User_19BPUNov 29 2011 — edited Nov 30 2011
Hi,

How to iterate nested lists in java? This is an example

private List<CustomerVO> getCustomerList(){
List<CustomerVO> list1 = new ArrayList<CustomerVO>();
List<CustomerVO> list2 = new ArrayList<CustomerVO>();
List<CustomerVO> list3 = new ArrayList<CustomerVO>();

CustomerVO customerVO1 = new CustomerVO();
customerVO1.setFirstName("Micheal")
customerVO1.setLastName("Bob")
list1.add(customerVO1);


CustomerVO customerVO2 = new CustomerVO();
customerVO2.setFirstName("Frank")
customerVO2.setLastName("Duke")
list2.add(customerVO2);

list3.addAll(list1);
list3.addAll(list2);

}


main() {

List<CustomerVO> customerList = getCustomerList();

// How to iterate and get the respective details from both List1 and List2?

for(List<CustomerVO> : customerList) // LIST1 .. this is not working

for(CustomerVO custVO1: customerList){ //LIST1 VO

..

..
}


}

Here how to get the values from list1 and list2?

Thanks.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 28 2011
Added on Nov 29 2011
11 comments
3,799 views