Modifier and Type | Method and Description |
---|---|
static <E> HashSet<E> |
newHashSet()
Creates a mutable, empty
HashSet instance. |
static <E> HashSet<E> |
newHashSetWithExpectedSize(int expectedSize)
Creates a
HashSet instance, with a high enough "initial capacity"
that it should hold expectedSize elements without growth. |
static <E> NavigableSet<E> |
unmodifiableNavigableSet(NavigableSet<E> set)
Returns an unmodifiable view of the specified navigable set.
|
public static <E> HashSet<E> newHashSet()
HashSet
instance.
Note: if mutability is not required, use ImmutableSet#of()
instead.
Note: if E
is an Enum
type, use EnumSet.noneOf(java.lang.Class<E>)
instead.
HashSet
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
HashSet
instance, with a high enough "initial capacity"
that it should hold expectedSize
elements without growth.
This behavior cannot be broadly guaranteed, but it is observed to be true
for OpenJDK 1.6. It also can't be guaranteed that the method isn't
inadvertently oversizing the returned set.expectedSize
- the number of elements you expect to add to the
returned setHashSet
with enough capacity to hold expectedSize
elements without resizingIllegalArgumentException
- if expectedSize
is negativepublic static <E> NavigableSet<E> unmodifiableNavigableSet(NavigableSet<E> set)
UnsupportedOperationException
.
The returned navigable set will be serializable if the specified navigable set is serializable.
set
- the navigable set for which an unmodifiable view is to be
returnedCopyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.