美文网首页
Java Collection

Java Collection

作者: robtomb_ | 来源:发表于2019-03-24 13:29 被阅读0次
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();

相关文章

  • Java Collection 体系

    概述 java.util.Collection => public interface Collection...

  • java面试题 --- 集合

    1. java 集合你了解吗?java 集合最顶层接口是 Collection 和 Map;Collection ...

  • Java自学-集合框架 Collection

    Java集合框架 Collection Collection是一个接口 步骤 1 : Collection Col...

  • java集合

    ================= Collection ======================Java集...

  • java集合详解

    java集合概述 Java 集合可分为 Collection 和 Map 两种体系 Collection接口:单列...

  • Java面试知识点总结-基础

    java基础 集合承继包含图 Collection vs Collections 首先,"Collection" ...

  • Java Collection集合 浅析

    java集合框架主要包含Collection和Map。这里主要解析一下collection。collection主...

  • Java 集合

    Collection Java标准库自带的java.util包提供了集合类:Collection,它是除Map外所...

  • java集合相关学习

    java集合框架解读 Java集合框架继承Collection和map两个接口,Collection的子类有Lis...

  • Java集合类详解

    Java集合类中Collection是最基本的集合接口,一个Collection代表一组Object。Java ...

网友评论

      本文标题:Java Collection

      本文链接:https://www.haomeiwen.com/subject/cukyvqtx.html