Collection框架
1.對(duì)于所有類(lèi)的間接父類(lèi)或者直接父類(lèi)都是Object的理解
默認(rèn)繼承Object類(lèi)
public class Test2{
public static void main(String args[]){
Test2 test = new Test2();
System.out.println(test.toString());
}
}
E:\mydemo\test1>javac Test2.java
E:\mydemo\test1>java Test2
Test2@15db9742
//getClass().getName() + '@' + Integer.toHexString(hashCode())
java.lang.Object
//怎么理解所有類(lèi)的間接父類(lèi)或者父類(lèi)是Object
class Object
protected Object clone();
boolean equals(Object o){return this == o};
Class<?> getClass();//Returns the runtime class of this Object.
//runtime class
int hashcode();//Returns a hash code value for the object.
String toString();//Returns a string representation of the object.
//getClass().getName() + '@' + Integer.toHexString(hashCode())
public class Test2{
public static void main(String args[]){
Test2 test = new Test2();
System.out.println(test.getClass());
}
}
E:\mydemo\test1>javac Test2.java
E:\mydemo\test1>java Test2
class Test2
interface Iterable<E>
boolean hasNext();
E next();
default void remove();//remove 當(dāng)前元素,之前必須 next 源碼-1會(huì)報(bào)錯(cuò)
interface Collection
boolean add(E e);
boolean addAll(Collection< ? extends E> c)
void clear();
boolean contains(Object o);
//returns true if and only if this collection contains at least
//one element e such that (o==null ? e==null : o.equals(e)).
//底層equals方法
boolean containsAll(Collection<?> c)
boolean equals(Object o);
int hasCode();
boolean isEmpty();
//true if this collection contains no elements
Iterator<E> iterator();
//an Iterator over the elements in this collection
boolean remove(Object o);
//removes an element e such that (o==null ? e==null : o.equals(e))
boolean remove(Collection<?> c);
boolean retatinAll(Collection<?> c);
int size();
//the number of elements in this collection
Object[] toArray();
//an array containing all of the elements in this collection
//注意是 object 并不能強(qiáng)制化為其他類(lèi)型
<T> T[] toArray(T[] a);
//String[] y = x.toArray(new String[x.size()]);
//傳入一個(gè)新的輸入脱拼,才可以類(lèi)型轉(zhuǎn)化
interface Set<E>
//set extends collection 的所有方法逝嚎,方法基本一致
interface List<E>
//list extends collection 的所有方法悯辙,方法基本一致
class List
//java.awt.List
class ArrayList
//implents List
void add(int index,E element);
//Inserts the specified element at the specified position in this list.
boolean addAll(int index,Collextion<? extends E> c)
boolean clone();
//Returns a shallow copy of this ArrayList instance.
ListIterator<E> listIterator()
E remove(int index);
//Removes the element at the specified position in this list.
void sort(Comparator c);
//Sorts this list according to the order induced by the specified Comparator.
List<E> subList(int fromindex,int toIndex);
class LinkedList
//雙向鏈表
void addFirst(E e);
void addLast(E e);
void get(int index);
void getFirst();
void getLast();
int indexOf(Object o);
ListIterator listIterator(int index)
E pop();
void push(E e);
Class HashSet
//和colection 差不多
Interface Map
void clear();
boolean containsKey(Object key);
boolean containsValue(Object value);
Set<Map.Entry<k,V> entrySet();
boolean equals(Object o);
V get(Object key);
int hashCode();
boolean isEmpty();
Set<K> keySet();
V put(K key,V value);
V remove(Object key);
boolean replace(K key,V oldValue, V newValue);
int size();
Collection<V> values();