Collection Factory Methods

suggest change

Versions

[{“Name”:“Java SE 9 (Early Access)”,“GroupName”:null}]

Introduction

The arrival of Java 9 brings many new features to Java’s Collections API, one of which being collection factory methods. These methods allow for easy initialization of immutable collections, whether they be empty or nonempty.

Note that these factory methods are only available for the following interfaces: List<E>, Set<E>, and Map<K, V>

Syntax

Parameters

Method w/ Parameter | Description | ——— | ——— |List.of(E e) | A generic type that can be a class or interface. |Set.of(E e) | A generic type that can be a class or interface. |Map.of(K k, V v) | A key-value pair of generic types that can each be a class or interface. |Map.of(Map.Entry<? extends K, ? extends V> entry) | A Map.Entry instance where its key can be K or one of its children, and its value can be V or any of its children. |

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Collection Factory Methods:
* Collection Factory Methods

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
155 Collection Factory Methods
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap