Java : SequencedSet with Examples
SequencedSet (Java SE 23 & JDK 23) in Java with Examples.
You will find code samples for most of the SequencedSet<E> methods.
Summary
A collection that is both a SequencedCollection and a Set. As such, it can be thought of either as a Set that also has a well-defined encounter order, or as a SequencedCollection that also has unique elements.
final SequencedSet<String> set = new LinkedHashSet<>();
set.addLast("a");
set.addLast("b");
set.addLast("c");
System.out.println(set); // [a, b, c]
System.out.println(set.reversed()); // [c, b, a]
set.addFirst("X");
set.addFirst("Y");
set.addFirst("Z");
System.out.println(set); // [Z, Y, X, a, b, c]
System.out.println(set.reversed()); // [c, b, a, X, Y, Z]
Methods
SequencedSet<E> reversed ()
Returns a reverse-ordered view of this collection.
final SequencedSet<String> set = new LinkedHashSet<>();
set.addLast("aaa");
set.addLast("bbb");
set.addLast("ccc");
System.out.println(set); // [aaa, bbb, ccc]
final var reversedSet = set.reversed();
System.out.println(reversedSet); // [ccc, bbb, aaa]
System.out.println(reversedSet.reversed()); // [aaa, bbb, ccc]
Methods declared in Collection
Methods declared in Iterable
Methods declared in SequencedCollection
addFirst, addLast, getFirst, getLast, removeFirst, removeLast
Please see the link below.
Methods declared in Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, spliterator, toArray, toArray
Please see the link below.
Related posts
- API Examples