1.对List的操作
Collections.nCopies(4, new StringAddress("Hello")));//复制4份
Collections.fill(list, new StringAddress("World!"));//替换容器中所有对象
2.Collection
// Make an array from the List:
Object[] array = c.toArray();
// Make a String array from the List:
String[] str = c.toArray(new String[0]);
3.享元(Flyweight design)
Countries.java
4.可选操作Optional Operation
Arrays.asList() 返回固定尺寸的List
Collections.unmodifiableList() 产生不可修改的列表
List<String> list = Arrays.asList("A B C D E F G H I J K L".split(" "));
test("Modifiable Copy", new ArrayList<String>(list));
test("Arrays.asList()", list);
test("unmodifiableList()",Collections.unmodifiableList(new ArrayList<String>(list)));
5.单向链表(简单实现)
Ex 模拟单向链表的增删(待编辑)
6.Implement Comparable
@Override
public int compareTo(Ex11 o) {
int res = this.count - o.count;
return res < 0 ? -1 : (res == 0 ? 0 : 1);
}
7. Deque
双向队列
8. 在java编程语言中,最基本的结构就是两种,一个是数组,另外一个是模拟指针(引用),所有的数据结构都可以用这两个基本结构来构造的,HashMap也不例外。HashMap实际上是一个“链表散列”的数据结构,即数组和链表的结合体。
9.java.util.Properties extends Hashtable<Object,Object>
10.SortedMap(TreeMap唯一实现)
Comparator comparator()
firstKey()
SortedMap subMap(K fromKey, K toKey) //唯一可以取子集的Map类
11.访问顺序排序
Map linkedMap = new LinkedHashMap<Integer, String>(16, 0.75f, true);
12. HashMap 的 put 与 HashSet 的 add
由于 HashSet 的 add() 方法添加集合元素时实际上转变为调用 HashMap 的 put() 方法来添加 key-value 对,当新放入 HashMap 的 Entry 中 key 与集合中原有 Entry 的 key 相同(hashCode() 返回值相等,通过 equals 比较也返回 true),新添加的 Entry 的 value 将覆盖原来 Entry 的 value,但 key 不会有任何改变,因此如果向 HashSet 中添加一个已经存在的元素,新添加的集合元素(底层由 HashMap 的 key 保存)不会覆盖已有的集合元素。
13.
HashCode作用
Equals作用
String的比较
14.对每个容器对象,底层数据分析(比如:LinkedList链表)
ArrayList
HashMap
HashSet
15.容器测试效率
对于List选择
ArrayList作为默认首选,如果需要经常表中间插入和删除,才去选择LinkedList
如果使用固定数量的元素,可以选择背后有数组支撑的List(Arrays.asList()产生的列表),也可选择真正的数组
对于set的选择
HashSet性能上总是比TreeSet好
对于插入操作,LinkedHashSet比HashSet的代价更高
16.Collections方法
17. Fail fast机制(快速报错)
final Entry<K,V> nextEntry() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
由所有HashMap类的“collection 视图方法”所返回的迭代器都是快速失败的:在迭代器创建之后,如果从结构上对映射进行修改,除非通过迭代器本身的 remove 方法,其他任何时间任何方式的修改,迭代器都将抛出 ConcurrentModificationException。
18. Holding references