Nested ArrayList in a set, nested ArrayList in a set

Source: Internet
Author: User

Nested ArrayList in a set, nested ArrayList in a set

1 import java. util. arrayList; 2 3 import com. heima. bean. person; 4 5 public class Demo5_ArrayListArrayList {6/* 7 * Set nested ArrayList case: one school has many classes and many others; traverse and output the public static void main (String [] args) {10 ArrayList <Person> school = new ArrayList <> () of all students in this school (); 11 ArrayList <Person> class1 = new ArrayList <> (); 12 class1.add (new Person ("Zhang San", 23); 13 class1.add (new Person ("Li Si ", 24); 14 class1.add (new Person ("", 25); 15 ArrayList <Person> class2 = new ArrayList <> (); 16 class2.add (new Person ("Zhang Sany", 23); 17 class2.add (new Person ("Li Siyi", 24 )); 18 class2.add (new Person ("Wang Wuyi", 25); 19 school. add (class1); 20 school. add (class2); 21 for (ArrayList <Person> outer: school) {22 for (Person in: outer) {23 System. out. println (in); 24} 25} 26 27} 28 29}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.