码迷,mamicode.com
首页 > 其他好文 > 详细

集合嵌套之ArrayList嵌套ArrayList

时间:2017-08-22 23:07:11      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:dem   imp   string   五一   ati   oid   log   util   stat   

 1 import java.util.ArrayList;
 2 
 3 import com.heima.bean.Person;
 4 
 5 public class Demo5_ArrayListArrayList {
 6     /*
 7      * 集合嵌套之ArrayList嵌套ArrayList 案例:一个学校有好多班级,一个班级又有好多人;遍历输出这个学校的所有人
 8      */
 9     public static void main(String[] args) {
10         ArrayList<ArrayList<Person>> school = new ArrayList<>();
11         ArrayList<Person> class1 = new ArrayList<>();
12         class1.add(new Person("张三", 23));
13         class1.add(new Person("李四", 24));
14         class1.add(new Person("王五", 25));
15         ArrayList<Person> class2 = new ArrayList<>();
16         class2.add(new Person("张三一", 23));
17         class2.add(new Person("李四一", 24));
18         class2.add(new Person("王五一", 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 }

 

集合嵌套之ArrayList嵌套ArrayList

标签:dem   imp   string   五一   ati   oid   log   util   stat   

原文地址:http://www.cnblogs.com/le-ping/p/7413756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!