Set&List&Map
Map
概述
An object that maps keys to values.
A map cannot contain duplicate keys; each key can map to at most one value.
Map将key映射到value;
Map的key不能重复,每个key只能映射一个value;
This interface takes the place of the <tt>Dictionary</tt> class, which was a totally abstract class rather than an interface.
Map替代了Dictionary;
The <tt>Map</tt> interface provides three <i>collection views</i>, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings.
The <i>order</i> of a map is defined as the order in which the iterators on the map's collection views return their elements.
Some map implementations, like the <tt>TreeMap</tt> class, make specific guarantees as to their order; others, like the <tt>HashMap</tt> class, do not.
Map提供3个views:key的Set集合、value的集合、k-v映射集合;
Map的实现:TreeMap(保证有序)、HashMap;
All general-purpose map implementation classes should provide two "standard" constructors:
a void (no arguments) constructor which creates an empty map, and a constructor with a single argument of type <tt>Map</tt>, which creates a new map with the same key-value mappings as its argument.
In effect, the latter constructor allows the user to copy any map, producing an equivalent map of the desired class.
Map实现类应该提供2个构造参数:
一个无参构造(创建空Map)、一个Map参数(创建与参数相同k-v的Map);
public interface Map<K,V> { V get(Object key); V put(K key, V value); V remove(Object key); Set<K> keySet(); Collection<V> values(); Set<Entry<K, V>> entrySet(); }
Set
概述
A collection that contains no duplicate elements.
More formally, sets contain no pair of elements <code>e1</code> and <code>e2</code> such that <code>e1.equals(e2)</code>, and at most one null element.
As implied by its name, this interface models the mathematical <i>set</i> abstraction.
Set不包含重复元素;
Set没有e1.equals(e2)的情况,至多一个null;
public interface Set<E> extends Collection<E> { Iterator<E> iterator(); }
List
概述
An ordered collection (also known as a <i>sequence</i>).
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.
List是一个有序集合;
Unlike sets, lists typically allow duplicate elements.
More formally, lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt> such that <tt>e1.equals(e2)</tt>, and they typically allow multiple null elements if they allow null elements at all.
list允许重复元素;
List允许多个null;
The <tt>List</tt> interface provides a special iterator, called a <tt>ListIterator</tt>, that allows element insertion and replacement, and bidirectional access in addition to the normal operations that the <tt>Iterator</tt> interface provides.
A method is provided to obtain a list iterator that starts at a specified position in the list.
List提供了一个特殊的iterator(ListIterator允许)
public interface List<E> extends Collection<E> { Iterator<E> iterator(); ListIterator<E> listIterator(); }