当前位置: 移动技术网 > IT编程>开发语言>Java > 第三次学JAVA再学不好就吃翔(part88)--ArrayList嵌套ArrayList

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

2020年07月13日  | 移动技术网IT编程  | 我要评论

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



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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网