Java集合之面试篇

鉴于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.(红黑树)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值