java数据结构实现类_Java的数据结构相关的类实现

8a6903ca13bcbc0778615c2e8cc1f2ba.png

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.

Returns an iterator over elements of type T.

Creates a Spliterator over the elements described by this Iterable.

Collection:

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

Modifier and TypeMethod and Description

boolean

Ensures that this collection contains the specified element (optional operation).

boolean

Adds all of the elements in the specified collection to this collection (optional operation).

void

Removes all of the elements from this collection (optional operation).

boolean

Returns true if this collection contains the specified element.

boolean

Returns true if this collection contains all of the elements in the specified collection.

boolean

Compares the specified object with this collection for equality.

int

Returns the hash code value for this collection.

boolean

Returns true if this collection contains no elements.

Returns an iterator over the elements in this collection.

default Stream

Returns a possibly parallel Stream with this collection as its source.

boolean

Removes a single instance of the specified element from this collection, if it is present (optional operation).

boolean

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

Retains only the elements in this collection that are contained in the specified collection (optional operation).

int

Returns the number of elements in this collection.

Creates a Spliterator over the elements in this collection.

default Stream

Returns a sequential Stream with this collection as its source.

Returns an array containing all of the elements in this collection.

 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

A map entry (key-value pair).

Modifier and TypeMethod and Description

void

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

Returns true if this map contains a mapping for the specified key.

boolean

Returns true if this map maps one or more keys to the specified value.

Returns a Set view of the mappings contained in this map.

boolean

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.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

default V

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

int

Returns the hash code value for this map.

boolean

Returns true if this map contains no key-value mappings.

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.

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

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.

Removes the mapping for a key from this map if it is present (optional operation).

default boolean

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

Returns the number of key-value mappings in this map.

Returns a Collection view of the values contained in this map.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值