码迷,mamicode.com
首页 > 编程语言 > 详细

Java的数据结构相关的类实现

时间:2017-08-31 18:03:54      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:sso   values   rms   tar   possibly   att   object   nsvalue   mod   

技术分享

 

Iterator:

迭代器接口,是Collection接口的父接口。Implementing this interface allows an object to be the target of the "foreach" statement. 也就是说,所有的Collection集合对象都具有foreach可遍历性。

Java 8 新增: forEach() 和 spliterator()

Modifier and TypeMethod and Description
default void forEach(Consumer<? super T> action)
Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
Iterator<T> iterator()
Returns an iterator over elements of type T.
default Spliterator<T> spliterator()
Creates a Spliterator over the elements described by this Iterable.

 

Collection:

是集合层级结构的根接口。一个collection代表一组object,也称为元素。有些collections允许重复元素,有些不允许。有些collections是有序的,有些是无序的。JDK没有提供这个接口的直接实现,而是提供了一些更具体的子接口,如Set,List。

Java 8 新增 :parallelStream(),removeIf(Predicate<? super E> filter),spliterator(),stream()

Modifier and TypeMethod and Description
boolean add(E e)
Ensures that this collection contains the specified element (optional operation).
boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection (optional operation).
void clear()
Removes all of the elements from this collection (optional operation).
boolean contains(Object o)
Returns true if this collection contains the specified element.
boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.
boolean equals(Object o)
Compares the specified object with this collection for equality.
int hashCode()
Returns the hash code value for this collection.
boolean isEmpty()
Returns true if this collection contains no elements.
Iterator<E> iterator()
Returns an iterator over the elements in this collection.
default Stream<E> parallelStream()
Returns a possibly parallel Stream with this collection as its source.
boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).
boolean removeAll(Collection<?> c)
Removes all of this collection‘s elements that are also contained in the specified collection (optional operation).
default boolean removeIf(Predicate<? super E> filter)
Removes all of the elements of this collection that satisfy the given predicate.
boolean retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).
int size()
Returns the number of elements in this collection.
default Spliterator<E> spliterator()
Creates a Spliterator over the elements in this collection.
default Stream<E> stream()
Returns a sequential Stream with this collection as its source.
Object[] toArray()
Returns an array containing all of the elements in this collection.
<T> T[] toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array



Map:

Map用于保存键值对,key和value都可以使任何饮用类型的数据。Map的key不允许重复,一个key映射至少一个value。

Map接口提供了三个collections,分别是key set,value collections还有key-value mapping set. Map的顺序就是迭代器迭代出来的顺序。

Java 8 新增:

Modifier and TypeInterface and Description
static interface  Map.Entry<K,V>
A map entry (key-value pair).
Modifier and TypeMethod and Description
void clear()
Removes all of the mappings from this map (optional operation).
default V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
default V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
default V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.
boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key.
boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value.
Set<Map.Entry<K,V>> entrySet()
Returns a Set view of the mappings contained in this map.
boolean equals(Object o)
Compares the specified object with this map for equality.
default void forEach(BiConsumer<? super K,? super V> action)
Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
V get(Object key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
default V getOrDefault(Object key, V defaultValue)
Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
int hashCode()
Returns the hash code value for this map.
boolean isEmpty()
Returns true if this map contains no key-value mappings.
Set<K> keySet()
Returns a Set view of the keys contained in this map.
default V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.
V put(K key, V value)
Associates the specified value with the specified key in this map (optional operation).
void putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map (optional operation).
default V putIfAbsent(K key, V value)
If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.
V remove(Object key)
Removes the mapping for a key from this map if it is present (optional operation).
default boolean remove(Object key, Object value)
Removes the entry for the specified key only if it is currently mapped to the specified value.
default V replace(K key, V value)
Replaces the entry for the specified key only if it is currently mapped to some value.
default boolean replace(K key, V oldValue, V newValue)
Replaces the entry for the specified key only if currently mapped to the specified value.
default void replaceAll(BiFunction<? super K,? super V,? extends V> function)
Replaces each entry‘s value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
int size()
Returns the number of key-value mappings in this map.
Collection<V> values()
Returns a Collection view of the values contained in this map.

Java的数据结构相关的类实现

标签:sso   values   rms   tar   possibly   att   object   nsvalue   mod   

原文地址:http://www.cnblogs.com/IvySue/p/7459385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!