黑马程序员技术交流社区

标题: arraylist嵌套arraylist [打印本页]

作者: ZhengJX    时间: 2015-10-10 22:45
标题: arraylist嵌套arraylist
  1. package com.heima.zuoye;

  2. import java.util.ArrayList;

  3. import com.heima.bean.Person;

  4. public class Demo5_DoubleList {
  5.         public static void main(String[] args) {
  6.                 ArrayList<ArrayList<Person>> list = new ArrayList<>();
  7.                
  8.                 ArrayList<Person> first = new ArrayList<>();
  9.                 first.add(new Person("金洋", 23));
  10.                 first.add(new Person("文悦", 24));
  11.                
  12.                 ArrayList<Person> second = new ArrayList<>();
  13.                 second.add(new Person("呵呵", 11));
  14.                 second.add(new Person("哈哈", 10));
  15.                
  16.                 list.add(first);
  17.                 list.add(second);
  18.                
  19.                 for(ArrayList<Person> a:list) {
  20.                         for(Person p : a) {
  21.                                 System.out.println(p);
  22.                         }
  23.                 }
  24.         }
  25. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2