天天看点

J2SE巩固-集合

跟随公司大牛一起面试了不少技术人员,有工作3-4年的有工作6年以上的。发现能令我们满意的太少,因此桌上简历是越堆越高。

技术基础也是面试的基础,这一关不通过,面试基本就结束。

集合是我们开发过程常用的一种类型,JDK为我们提供了Collection,Map等集合类型,盗用CSDN一位博主的图

J2SE巩固-集合

经常用的我们有ArrayList/HashSet/HashMap等,

List重复有序

Set不重复无序

Map提供键值对

但我们有时会需要一些特殊需求,比如要求List既有序也不重复,或者Set不重复也有序,Map按key有序输出,或者线程安全的等。从上面的图很容易分析出,JDK是有提供这样能力的api和相应的实现类。

一、List 接口

An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all。

List能够精确控制每个被插入的元素的位置,然后通过整数index来获取。并且允许多个重复元素。

List接口的实现类有

AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector

常用的有ArrayList LinkedList Vector CopyOnWriteArrayList