Java集合之面试篇

来源:互联网 发布:网络实名制 郭德纲 编辑:程序博客网 时间:2024/03/29 14:58

鉴于Android面试中对java基础很是看中而集合又是基础中的核心部分,所以有必要好好学习下集合的相关知识,这篇博客的原则如下

不分析任何源码方法,只看源码注释

这里写图片描述

Iterable

public interface Iterable<T>{}Implementing this interface allows an object to be the target of the "for-each loop" statement(通过实现这个接口允许一个对象成为foreach循环语句的目标)

Collection

public interface Collection<E> extends Iterable<E> {}A collection * represents a group of objects, known as its <i>elements</i>.  Some * collections allow duplicate elements and others do not.  Some are ordered * and others unordered.  The JDK does not provide any <i>direct</i> * implementations of this interface: it provides implementations of more * specific subinterfaces like <tt>Set</tt> and <tt>List</tt> (代表一组对象,为人所知的是他的元素集,一些集合允许重复的元素,另外一些不允许,一些是有顺序的而另外一些是无序的,JDK不提供这个接口的直接实现,他提供更多子接口(比如List和Set)实现)

List

public interface List<E> extends Collection<E> {}An ordered collection (also known as a <i>sequence</i>)(有序集合)Unlike sets, lists typically allow duplicate elements(与Set不同,List允许重复的元素)

Set

public interface Set<E> extends Collection<E> {}A collection that contains no duplicate elements.(不包含重复的集合)

ArrayList

public class ArrayList<E> extends AbstractList<E>        implements List<E>, RandomAccess, Cloneable, java.io.Serializable{}Resizable-array implementation of the <tt>List</tt> interface(实现List接口的长度可变数组)Note that this implementation is not synchronized.(线程不安全)

LinkedList

public class LinkedList<E>    extends AbstractSequentialList<E>    implements List<E>, Deque<E>, Cloneable, java.io.Serializable{} Doubly-linked list implementation of the {@code List} and {@code Deque} interfaces(List和Deque的双链表实现)Note that this implementation is not synchronized.(这个类不是线程安全的)

Vector

public class Vector<E>    extends AbstractList<E>    implements List<E>, RandomAccess, Cloneable, java.io.Serializable{}The {@code Vector} class implements a growable array of objects (数组对象长度可变)几乎等同于ArrayList但是这个类在方法名前声明了“synchronized”,所以是线程安全的

关于HashMap和HashTable的介绍请看我的这篇博客

HashMap和HashTable

HashSet

public class HashSet<E>    extends AbstractSet<E>    implements Set<E>, Cloneable, java.io.Serializable{}This class implements the <tt>Set</tt> interface, backed by a hash table  (actually a <tt>HashMap</tt> instance).(很明显 HashSet就是建立在HashMap的基础上)Note that this implementation is not synchronized.(线程不安全)

TreeMap

A Red-Black tree based {@link NavigableMap} implementation.(红黑树)
原创粉丝点击