JAVA问题记录:List与Map

本文深入探讨了Java集合框架中ArrayList和LinkedList的底层实现,ArrayList基于数组,而LinkedList通过内部类实现链表结构。同时,分析了HashMap的数据结构及其线程不安全问题,以及Hashtable作为线程安全的替代选项。此外,提到了TreeMap的有序特性。
摘要由CSDN通过智能技术生成

        /*
           transient Object[] elementData; // non-private to simplify nested class access
           ArrayList<>() 底层原理是数组
         */
        List<Integer> list=new ArrayList<>();
        /*
        private static class Node<E> {
            E item;
            Node<E> next;
            Node<E> prev;
            Node(Node<E> prev, E element, Node<E> next) {
            this.item = element;
            this.next = next;
            this.prev = prev;
        }
        底层原理是自定义了内部类,链表结构
    }
         */
        List<Integer> list2=new LinkedList<>();

        /*
        HashMap即是采用了链地址法,也就是数组+链表的方式。

        *HashMap被改变的次数,由于HashMap非线程安全,在对HashMap进行迭代时,
        如果期间其他线程的参与导致HashMap的结构发生变化了(比如put,remove等操作),
        需要抛出异常ConcurrentModificationException
        transient int modCount;
         */
        Map<String,Integer> map=new HashMap();

        /*
        Hashtable 的函数都是同步的,这意味着它是线程安全的。它的key、value都不可以为null。此外,Hashtable中的映射不是有序的。
         public synchronized V get(Object key)
         public synchronized V put(K key, V value)
         */
        Map<String, String> maptable=new Hashtable<>();

        Map<String,Integer> map2=new TreeMap<>();
    }
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值