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

Iterator:

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

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

Modifier and Type Method 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 Type Method 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 Type Interface and Description
static interface  Map.Entry<K,V>

A map entry (key-value pair).

Modifier and Type Method 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.

时间: 2024-08-11 06:03:14

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

21、java中和日期相关的类

一.Data及其常用API 1.简介 Java中的时间使用标准类库的java.util.Date,其表示特定的瞬间,精确到毫秒.是用距离一个固定时间点的毫秒数(可正可负,long类型)表达一个特定的时间点. 固定的时间点叫纪元(epoch),是UTC时间1970年 1月 1日 00:00:00  ,UTC(Universal Time Coordinated世界调整时间)与GMT(Greenwich Mean Time格林威治时间)一样,是一种具有实际目的的科学标准时间. 因为Date的设计具有

Java数据结构Map,List,Set及Queue相关的类图

闲来无事,把util包中相关的数据结构的类图及其关系画了一下,给大家分享一下. 总览图:  Map:  List and Set: Queue: Java数据结构Map,List,Set及Queue相关的类图

JAVA之IO技术相关Properties类 存储配置文件信息

package ioTest.io3; /* * Properties存储配置文件信息 * 1.文件信息--------------------------- * 2.根据文件信息获取key和value---|流| * 3.将key,value的之对应存储到properties对象中 */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileOu

JAVA之IO技术相关Properties类的使用

package ioTest.io3; /*Properties是hashtable的子类. * 也就是说它具备map集合的特点,而且它里面存储的键值对都是字符串 * 是集合中和io技术结合的一个容器 * * 该对象的特点是可以用于键值对形式的配置文件 */ import java.util.Properties; public class PropertiesDemo { public static void main(String[] args) { // TODO Auto-generat

Java数据结构学习—Collections类

java.util 类 Collections java.lang.Object java.util.Collections public class Collections extends Object 此类完全由在 collection 上进行操作或返回 collection 的静态方法组成.它包含在 collection 上操作的多态算法,即"包装器",包装器返回由指定 collection 支持的新 collection,以及少数其他内容. 如果为此类的方法所提供的 colle

java项目——数据结构实验报告

java项目——数据结构总结报告 20135315  宋宸宁 实验要求 1.用java语言实现数据结构中的线性表.哈希表.树.图.队列.堆栈.排序查找算法的类. 2.设计集合框架,使用泛型实现各类. 3.API的编写,并导出. 4.使用TDD模式,对程序进行测试,利用TestSuite将各测试类整合到一起. 5.与小组成员实现代码的整合. 实验设计过程 首先自学集合框架章节的内容,初步设计相关的类. 根据数据结构课本的章节分类,实验各数据结构类. 在类的编写过程中,经过老师的指导,我准备使用泛型

java基础知识-对象和类

前言: 因为要准备Java面试,所有将java基础知识点重新复习一遍,主要笔记来源于菜鸟教程和java核心技术的书籍中,也有一些博客上的资料(这些只供我个人学习使用) Java 对象和类 对象:对象是类的一个实例,有状态和行为.例如,一条狗是一个对象,它的状态有:颜色.名字.品种:行为有:摇尾巴.叫.吃等. 类:类是一个模板,它描述一类对象的行为和状态. 下图中男孩女孩为类,而具体的每个人为该类的对象: 1.Java中的对象 现在让我们深入了解什么是对象.看看周围真实的世界,会发现身边有很多对象

Java基本数据结构总结

一直没有很仔细的系统学习Java,之前一直用的是python和c/c++,但是既然要走上大数据的道路,那么一定逃脱不开java的.下面在网上找到一些资料并结合相关的书进行整理总结. java.util包,包含集合框架.遗留的 collection 类.事件模型.日期和时间设施.国际化和各种实用工具类(字符串标记生成器.随机数生成器和位数组.日期Date类.堆栈Stack类.向量Vector类等).集合类.时间处理模式.日期时间工具等各类常用工具包.下面要介绍的Java版的数据结构就是在这个包中.

java 常用数据结构

本章介绍Java的实用工具类库java.util包.在这个包中,Java提供了一些实用的方法和数据结构.例如,Java提供日期(Data)类.日 历(Calendar)类来产生和获取日期及时间,提供随机数(Random)类产生各种类型的随机数,还提供了堆栈(Stack).向量 (Vector) .位集合(Bitset)以及哈希表(Hashtable)等类来表示相应的数据结构. 图1.1给出了java.util包的基本层次结构图.下面我们将具体介绍其中几个重要的类. ┌java.util.BitS