## JAVA12笔记 集合嵌套与HashSet的学习

本文详细探讨了JAVA12中的集合嵌套概念,并深入讲解了HashSet和LinkedHashSet的特性与用法,包括它们的介绍、实例应用及区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.补充例子
Integer[] arr = {10,20,30};
List integer = Arrays.aslist(arr);
Integer[] arr2 = {10,20,30};
Integer[] arr3 = {10,20,30};
Integer[] arr4 ={10,20,30};
List integer1 = Arrays.aslist(arr2,arr3,arr4);
// 如果是通过aslist()方法转换过来的集合,不能往集合中添加元素,或删除元素
//只能获取元素
List string = Arrays.aslist("a","b","c");

2.集合嵌套例子
public class MyTest{
    public static void main(String[] args){
        //我们班有学生,每一个学生是不是一个对象,所以我们可以使用一个集合表示我们班级的学生 Arraylist
        //但是,我们还有班级,每个班级也算是一个集合
        //而我们有多个Arraylist,也要用集合存储
        //Student类我们已经设定好
        Student s1 = new Student("张三"19);
        Student s2 = new Student("李二"20);
        Student s3 = new Student("赵四"21);
        Student s4 = new Student("王五"22);
        Student s5 = new Student("刘一"23);
        Student s6 = new Student("林二"24);
        Student s7 = new Student("楼三"18);
        ArrayList javalist = new Arraylist();
        javalist.add(s1);
        javalist.add(s2);
        javalist.add(s3);
        ArrayList weblist = new Arraylist();
        weblist.add(s4);
        weblist.add(s5);
        ArrayList pythonlist = new Arraylist();
        weblist.add(s6);
        weblist.add(s7);
        ArrayList  maxlist = new Arraylist();
        maxlist.add(javalist);   
        maxlist.add(weblist); 
        maxlist.add(pythonlist);
        for(int i = 0;i<maxList.size();i++){
            ArrayList students = maxList.get(i);
            for(int j= 0;j<students.size();j++){
                Stuednt stuednt1 = students.get(j);
                System.out.println(Student.getName()+"====="+Student.getAge());
                    
            }
        }
    }
}
开发步骤:开发文档,需求文档
统一开发环境:win7 JDK MySQL5.5 开发工具IDEA
登录注册
分层开发:JavaEE三层结构
MVC 开发模式
View 视图
Controller控制器
3.HashSet的介绍
//set 元素唯一
//HasgSet 底层数据结构是哈希表(数组+链表JDK1.7 JDK1.数组+链表+二叉树)
//HashSet元素无序,且唯一 ,内部重写了equals()方法
//哈希表是新华字典
//LinkedHashSet
//treeSet
HashSet<String> set = new HashSet<>();
set.add("a");
set.add("b");
set.add("c");
set.add("d");
set.add("d");
for(String s :set){
    System.out.println(s);
   
}
4.LinkedHashset的介绍
//数据结构 有两个链表和哈希表
//链表保证有序,哈希表保证元素唯一
//A:LinkedHashset的概述:元素有序,并且唯一
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值