Java常用集合:List、Set、Map
由下面可以看到:三者都是接口,常用实现类如下介绍。
而Iterator和Collection是这些接口的父接口(不包括Map,Map不继承任何接口)
父接口Iterator
public interface Iterable<T>
父接口Collection
public interface Collection<E> extends Iterable<E>
一、List
特点:线性表方式存储,可重复有索引的单列表,可以使用for循环遍历
public interface List<E> extends Collection<E>
1、ArrayList
特点:数组方式存储
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable
2、LinkedList
特点:链式存储
public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, java.io.Serializable
二、Set
特点:不可重复无索引的单列表,并且不保证顺序,不可以使用for循环遍历,可以使用增强for循环或者迭代器遍历
public interface Set<E> extends Collection<E>
1、HashSet
public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java.io.Serializable
2、TreeSet
特点:低层由链表和Hash表组成,相比于HashSet它存储的对象是有序的,但也不可重复,默认情况下自然排序,也可以使用比较器进行排序。对于自定义实体类要实现Comparable接口,并重写compareTo方法定义排序规则。
public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable
三、Map
特点:使用键值对存储,双列
public interface Map<K,V>
1、HashMap
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable
2、TreeMap
public class TreeMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>, Cloneable, java.io.Serializable
几种集合关系: ![在这里插入图片描述](https://img-blog.csdn.net/20160126094706606#pic_center)
图片来源:https://blog.csdn.net/lovesummerforever/article/details/50585286