Logo

Programming-Idioms

History of Idiom 118 > diff from v57 to v58

Edit summary for version 58 by programming-idioms.org:
[Java] +DemoURL

Version 57

2021-01-07, 11:03:53

Version 58

2021-01-07, 11:28:19

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Variables
y,x
Variables
y,x
Imports
import java.util.Set;
import java.util.HashSet;
Imports
import java.util.Set;
import java.util.HashSet;
Code
Set<T> y = new HashSet<T>(x);
Code
Set<T> y = new HashSet<T>(x);
Comments bubble
x is a Collection<T>, e.g. a List<T>.
Elements of x and y have the same type T.
Comments bubble
x is a Collection<T>, e.g. a List<T>.
Elements of x and y have the same type T.
Doc URL
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashSet.html#%3Cinit%3E(java.util.Collection)
Doc URL
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashSet.html#%3Cinit%3E(java.util.Collection)
Origin
https://stackoverflow.com/a/1429869/871134
Origin
https://stackoverflow.com/a/1429869/871134
Demo URL
https://repl.it/@ProgIdioms/TalkativeClumsyEmulators