/*
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<>();
}
JAVA问题记录:List与Map
本文深入探讨了Java集合框架中ArrayList和LinkedList的底层实现,ArrayList基于数组,而LinkedList通过内部类实现链表结构。同时,分析了HashMap的数据结构及其线程不安全问题,以及Hashtable作为线程安全的替代选项。此外,提到了TreeMap的有序特性。

被折叠的 条评论
为什么被折叠?



