Java Collection

2019-03-24  本文已影响0人  robtomb_
Collection框架

1.对于所有类的间接父类或者直接父类都是Object的理解
默认继承Object类

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

//怎么理解所有类的间接父类或者父类是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 当前元素,之前必须 next 源码-1会报错

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 并不能强制化为其他类型

<T> T[] toArray(T[] a);
//String[] y = x.toArray(new String[x.size()]);
//传入一个新的输入,才可以类型转化

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();
上一篇 下一篇

猜你喜欢

热点阅读