Logo

Programming-Idioms

History of Idiom 119 > diff from v15 to v16

Edit summary for version 16 by :
[Java] Original ordering is not preserved.

Version 15

2016-02-25, 22:26:21

Version 16

2016-03-20, 15:08:53

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Imports
import java.util.HashSet;
import java.util.List;
Imports
import java.util.HashSet;
import java.util.List;
Code
Set<T> uniques = new HashSet<>(x);
x.clear();
x.addAll(uniques);
Code
Set<T> uniques = new HashSet<>(x);
x.clear();
x.addAll(uniques);
Comments bubble
This uses the same List instance, emptied and then refilled.
Comments bubble
This uses the same List instance, emptied and then refilled.
Original ordering is not preserved.