-
Collection
remove removeAll retainAll(修改当前集合为交集) equals hashCode toArray(返回数组) iterator add addAll isEmpty size clear contains(调用obj对象所拥有的equals方法) containsAll
-
Collections
Collections.reverse(List)
Collections.sort
Collections.sort(List, Comparator)
Collections.max
Collections.max(List, Comparator)
min
frequency(Collection, obj)
出现次数copy
synchronizedXxx
-
Iterator
hasNext
next
(最开始在第一个元素之前 指针先下移并返回对应的元素)remove
while (hasNext) { next; } for (Object obj : list) { obj++; //因为obj是局部变量 所以list中的元素不变 }
-
List
add(index, element) addAll(index, collection) get(index) indexOf(obj) 首次出现 没有-1 lastIndexOf remove(index) 按索引 set(index, element) List subList(int from, int to)
-
Set
没有定义额外的方法 向Set方法添加的元素需要重写hashcode
和equals
-
Map
put putAll get remove(obj) clear size containsKey containsValue isEmpty equals(Map)
- 遍历
key Set set = map.keySet()
- 遍历
value Collection values = map.values()
- 遍历
key-value Set set = map.entrySet()
foreach(Map.Entry i : set) { i.getKey i.getValue }
- 遍历
-
有序可重复
-
ArrayList
线程不安全 效率高 初始化10 1.5倍扩容JDK8
中初始化为空 第一次add
时为10 -
LinkedList
底层使用双向链表 -
Vector
古老实现类 线程安全 -
HashSet
线程不安全 可以存储null 无序性HashCode
不可重复equals 7上8下 初始化16
添加a计算哈希值 判断此位置上的链表是否哈希值相同 如果相同 比较equals 如果都不同则插入a
-
LinkedHashSet
双向链表 遍历内部数据时 可以按照添加的顺序 -
TreeSet
用红黑树存储 放入的数据是同一类可排序的 按照添加的类的属性排序 在此容器中判断是否相同不用equals
而用compareTo
返回0、compare
返回0 -
TreeSet t = new TreeSet(new Comparator() {})
-
Map
-
HashMap
线程不安全 效率高 可以存储null
的key/value
为
Entry[]
初始化16 计算key的hashcode
和equals
比较是否相同扩容为2倍
JDK8
为Node[]
开始为空 第一次添加为16链表大于8且数组长度大于64 则变为红黑树 加载因子0.75 扩容:负载因子乘以长度 超过长度且存储的位置在数组上非空则扩容
-
LinkedHashMap
继承了HashMap的Node
增加了before
和after
-
TreeMap
key
为同一类对象 按照key
使用自然排序或定制排序 底层红黑树 -
Hashtable
古老的 线程安全 效率低 不可以存储null的key/value -
Properties key和value都是String类型
-
a=b
不要加空格class Test2 { public static void main(String[] args) throws Exception { Properties properties = new Properties(); FileInputStream file = new FileInputStream("jdbc.properties"); properties.load(file); String name = properties.getProperty("name"); System.out.println(name); properties.setProperty("name2", "hhh"); name = properties.getProperty("name"); System.out.println(name); file.close(); } } class Test2 { public static void main(String[] args) throws Exception { Properties properties = new Properties(); ClassLoader classLoader = Test2.class.getClassLoader(); //默认在src下面 方式1在工程下 InputStream in = classLoader.getResourceAsStream("jdbc.properties"); properties.load(in); String name = properties.getProperty("name"); System.out.println(name); properties.setProperty("name2", "hhh"); name = properties.getProperty("name"); System.out.println(name); } }