日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

集合嵌套存储和遍历元素的示例

發(fā)布時間:2025/7/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 集合嵌套存储和遍历元素的示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 /** 2 * @Auther: lzy 3 * @Date: 2018/12/12 16:07 4 * @Description: 集合嵌套存儲和遍歷元素的示例 5 */ 6 public class ListTest { 7 public static void main(String[] args) { 8 //創(chuàng)建大集合 9 ArrayList<ArrayList<Student>> bigArrayList = new ArrayList<ArrayList<Student>>(); 10 //創(chuàng)建第一個小集合 11 ArrayList<Student> firstArrayList = new ArrayList<Student>(); 12 //創(chuàng)建學生 13 Student s1 = new Student("fff",22); 14 Student s2 = new Student("hhh",21); 15 Student s3 = new Student("nnn",20); 16 //把學生存儲到第一個小集合中 17 firstArrayList.add(s1); 18 firstArrayList.add(s2); 19 firstArrayList.add(s3); 20 //把第一個小集合存儲到大集合中 21 bigArrayList.add(firstArrayList); 22 //創(chuàng)建第二個小集合 23 ArrayList<Student> secondArrayList = new ArrayList<Student>(); 24 Student s21 = new Student("sss",22); 25 Student s22 = new Student("xxx",21); 26 Student s23 = new Student("zzz",20); 27 secondArrayList.add(s21); 28 secondArrayList.add(s22); 29 secondArrayList.add(s23); 30 bigArrayList.add(secondArrayList); 31 //遍歷大集合 32 for (ArrayList<Student> arrayList:bigArrayList){ 33 //遍歷小集合 34 for (Student s:arrayList){ 35 System.out.println(s.getName()+","+s.getAge()); 36 } 37 38 } 39 40 41 } 42 }

?

轉載于:https://www.cnblogs.com/lzy-417/p/10109201.html

總結

以上是生活随笔為你收集整理的集合嵌套存储和遍历元素的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。