遍历嵌套集合
来源:互联网 发布:设计软件 logo cdr 编辑:程序博客网 时间:2024/06/05 05:57
package niu.cheng5;
import java.util.ArrayList;
import java.util.Iterator;
//遍历嵌套集合
public class ArrayListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<ArrayList<Student>> a=new ArrayList<ArrayList<Student>>();
ArrayList<Student> a2=new ArrayList<Student>();
ArrayList<Student> a3=new ArrayList<Student>();
ArrayList<Student> a4=new ArrayList<Student>();
Student s1=new Student("axx",10);
Student s2=new Student("bxx",11);
Student s3=new Student("cxx",12);
Student s4=new Student("dxx",13);
Student s5=new Student("exx",11);
Student s6=new Student("fxx",12);
Student s7=new Student("gxx",13);
Student s8=new Student("hxx",11);
Student s9=new Student("ixx",12);
Student s10=new Student("jxx",13);
a2.add(s1);
a2.add(s2);
a2.add(s3);
a2.add(s4);
a3.add(s5);
a3.add(s6);
a3.add(s7);
a4.add(s8);
a4.add(s9);
a4.add(s10);
a.add(a2);
a.add(a3);
a.add(a4);
for(ArrayList<Student> x:a){
/*
//方式1
for(int n=0;n<x.size();n++){
Student s=x.get(n);
System.out.println(s.getName()+"--"+s.getAge());
}
*/
/*
//方式2
for(Student y:x){
System.out.println(y.getName()+"--"+y.getAge());
}
*/
//方式3
Iterator<Student> l=x.iterator();
while(l.hasNext()){
Student s=l.next();
System.out.println(s.getName()+"--"+s.getAge());
}
}
}
}
import java.util.ArrayList;
import java.util.Iterator;
//遍历嵌套集合
public class ArrayListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<ArrayList<Student>> a=new ArrayList<ArrayList<Student>>();
ArrayList<Student> a2=new ArrayList<Student>();
ArrayList<Student> a3=new ArrayList<Student>();
ArrayList<Student> a4=new ArrayList<Student>();
Student s1=new Student("axx",10);
Student s2=new Student("bxx",11);
Student s3=new Student("cxx",12);
Student s4=new Student("dxx",13);
Student s5=new Student("exx",11);
Student s6=new Student("fxx",12);
Student s7=new Student("gxx",13);
Student s8=new Student("hxx",11);
Student s9=new Student("ixx",12);
Student s10=new Student("jxx",13);
a2.add(s1);
a2.add(s2);
a2.add(s3);
a2.add(s4);
a3.add(s5);
a3.add(s6);
a3.add(s7);
a4.add(s8);
a4.add(s9);
a4.add(s10);
a.add(a2);
a.add(a3);
a.add(a4);
for(ArrayList<Student> x:a){
/*
//方式1
for(int n=0;n<x.size();n++){
Student s=x.get(n);
System.out.println(s.getName()+"--"+s.getAge());
}
*/
/*
//方式2
for(Student y:x){
System.out.println(y.getName()+"--"+y.getAge());
}
*/
//方式3
Iterator<Student> l=x.iterator();
while(l.hasNext()){
Student s=l.next();
System.out.println(s.getName()+"--"+s.getAge());
}
}
}
}
0 0
- 遍历嵌套集合
- 集合的嵌套遍历
- * 集合的嵌套遍历
- 集合嵌套及遍历,随机数
- 集合框架-集合的嵌套遍历
- 集合框架-集合的嵌套遍历(HashMap嵌套HashMap)
- 集合框架-集合的嵌套遍历(HashMap嵌套ArrayList)
- 集合框架-集合的嵌套遍历(ArrayList嵌套HashMap)
- 集合框架-集合的嵌套遍历(多层嵌套)
- c标签遍历嵌套的List集合
- 双列集合Map的嵌套遍历
- c标签遍历集合嵌套的List集合
- 黑马程序员---ArrayList集合嵌套HashMap集合并遍历
- strust2 ognl或者el表达式遍历嵌套list集合
- java的集合嵌套及三种遍历
- Java中ArrayList集合嵌套存储和遍历
- 【我的Java笔记】ArrayList集合的遍历嵌套
- 【我的Java笔记】集合的遍历嵌套
- Computer Vision: Algorithms and Applications(学习笔记二)--geometric transformations
- 可变参数
- 编程折腾记
- 修改cmd字体为Consolas
- mysql select中子查询中使用强制索引的优化案例
- 遍历嵌套集合
- 2015 10 28  函数
- UML之初识
- 《how tomcat works》第一章 构建一个简单的web服务器
- 【树项目3 - 利用二叉树遍历思想解决问题——第10周】
- 泛型
- 进击的KFC:OC(七)类的扩展
- java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticL
- [C++11]二叉树前序、中序和后序遍历2(非递归)