Java基础:集合List、Map、Set(超详细版)

集合体系概述


Collection常用方法

补充:addAll()

Collection的遍历方式

迭代器


增强for(空集合可以,null不可以)


lambda

集合对象存储对象原理

遍历方式的区别

List集合

特点、特有方法

遍历方式

(同上)

ArrayList底层原理



LinkedList底层原理



手写链表

java 复制代码
/**
 * 手写链表
 */
public class MyLinkedList<E> {

    private int size = 0;
    Node<E> first;

    public static class Node<E> {
        E item;
        Node<E> next;
        public Node(E item, Node<E> next){
            this.item = item;
            this.next = next;
        }
    }

    public boolean add(E e) {
        Node<E> newNode = new Node<>(e, null);

        if(first == null) {
            first = newNode;
        } else {
            Node<E> temp = first;
            while(temp.next != null) {
                temp = temp.next;
            }
            temp.next = newNode;
        }

        size++;

        return true;
    }


    @Override
    public String toString() {
        StringJoiner s = new StringJoiner(",", "[", "]");
        Node<E> temp = first;
        while(temp != null) {
            s.add(temp.item + "");
            temp = temp.next;
        }
        return s.toString();
    }

    public int size(){
        return size;
    }

}

class Test {
    public static void main(String[] args) {
        MyLinkedList<String> list = new MyLinkedList<>();
        list.add("1号客人");
        list.add("2号客人");
        list.add("3号客人");
        list.add("4号客人");

        System.out.println(list);
    }
}

Set集合

特点

HashSet底层原理




了接下数据结构(树)


查询性能提高:排序



去重机制


LinkedHashSet底层原理-有序

TreeSet底层原理-排序


*优先选择

Map集合

概述



常用方法

遍历方法



HashMap-原理



LinkedHashMap-原理

TreeMap-原理

相关推荐
SQL-First布道者5 分钟前
全面解构传统持久层框架,拥抱真正的 SQL-First
java·数据库·spring boot·sql·spring·mybatis·spring jdbc
归去来 兮13 分钟前
Python爬虫爬取数据案例
开发语言·爬虫·python
ShineWinsu15 分钟前
对于 C++:C++20中Concept(概念) 与 Coroutine(协程)的解析
linux·开发语言·网络·c++·c++20·epoll
ly768915 分钟前
C 语言从入门到进阶:语法、指针、内存管理与工程实践详解
c语言·开发语言
quantdash_cc32 分钟前
历史数据断层与REST请求慢到崩溃?QuantDash高性能量化数据API终极解决方案
开发语言·python·缓存·php·量化·quantdash
breeze jiang33 分钟前
Next.js 16 App Router 实战:从 About、Blog 动态路由到全局 404
开发语言·javascript·ecmascript
熊野君36 分钟前
Prompt / RAG / 规则 / Skills —— 定位、协作与实现路线
开发语言·python
小蒜学长38 分钟前
vue旅游攻略网站(代码+数据库+LW)
java·数据库·vue.js·spring boot·后端·旅游
凤山老林1 小时前
轻量级规则引擎落地:Spring Boot 集成 LiteFlow 实现动态业务编排与热更新
java·spring boot·后端·规则引擎·liteflow
夏贰四1 小时前
管控数据加载调度如何规避任务冲突?数据加载运维监控体系该如何搭建?
java·大数据·运维