1. List
- set(int index, E element) method has a return value, it's the original value at this index.
2. Collection is an interface, Collections is a class
- All methods in Collections are static. When you call these methods, you can use Collections.methodname(). Usually methods in Collections are static, List is parameter in these methods.
- common methods are “sort, reverse, binarysearch, shuffle”
3. Comparable
- Comparable is an interface, there is only one method inside: int compareTo(T o). 这里comparable<T>
4. once redefine equals() method, you must also redefine hashcode(). Cause, in map when use equals will cost too much time, compare hashcode may be more convenient.
5. Map
- V put(K key, V value) will return value, because it's possible that this key existed and this value will be replace. So the original value will be returned.
- V remove(K ket, V value) will return the value that will be removed
- void putAll(Map<K, V>, m), copy a specific map into this map
6. Autoboxing and unboxing
- When Java automatically convert primitive type to its corresponding wrapper object class. unboxing is the opposite operation.
7. Generic
- 范型出现以后可以定义collection中添加特定类型的对象,一旦添加不符合条件的对象,在complie time就会报错。这种操作将run time errors 提前到了 compile time.
- 加入type parameter, 例如ArrayList<String> l = new ArrayList<String>(). 规定了只能对string类型对象进行操作
- 范型消除了很多强制转化,范型出现前所有对象都是object类型,需要强制转化才能转化成需要的类型,范型出现后,所有的对象都有特定的类型。
- 范型出现以前,装入collection的对象都被当作object类型,从而失去了自己原有的类型,而取出时又需要被转化成特定的类型。效率低,容易产生错误。
- 使得程序更加readable and stable.