第三次学JAVA再学不好就吃翔(part88)--ArrayList嵌套ArrayList

2022-08-06,,,

学习笔记,仅供参考,有错必纠


ArrayList嵌套ArrayList

  • 举个例子
package com.guiyang.object;

import java.sql.Array;
import java.util.ArrayList;


import com.guiyang.bean.People;

public class Demo5_ArrayListArrayList {

	public static void main(String[] args) {
		ArrayList<ArrayList<People>> list = new ArrayList<>();
		
		ArrayList<People> first = new ArrayList<>();
		first.add(new People("Ada", 21));
		first.add(new People("Jack", 22));
		first.add(new People("Petty", 19));
		
		ArrayList<People> second = new ArrayList<>();
		second.add(new People("小白", 18));
		second.add(new People("小黑", 19));
		
		list.add(first);
		list.add(second);
		
		for (ArrayList<People> arrayList : list) {
			for (People people : arrayList) {
				System.out.println(people);
			}	
		}
	}
}

输出:

People [name=Ada, age=21]
People [name=Jack, age=22]
People [name=Petty, age=19]
People [name=小白, age=18]
People [name=小黑, age=19]

本文地址:https://blog.csdn.net/m0_37422217/article/details/107241601

《第三次学JAVA再学不好就吃翔(part88)--ArrayList嵌套ArrayList.doc》

下载本文的Word格式文档,以方便收藏与打印。