Top Inners Fields Constructors Methods
org.eclipse.collections.impl.map.sorted.immutable

public Class ImmutableTreeMap<K, V>

extends AbstractImmutableSortedMap<K, V>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.lang.reflect.Array, java.util.AbstractSet, .Arrays, .Collection, .Comparator, .Iterator, .Map, .NoSuchElementException, .Objects, .Set, .SortedMap, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.block.procedure.Procedure2, org.eclipse.collections.api.factory.SortedMaps, .SortedSets, org.eclipse.collections.api.map.ImmutableMap, org.eclipse.collections.api.map.sorted.ImmutableSortedMap, .MutableSortedMap, org.eclipse.collections.api.set.sorted.MutableSortedSet, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.impl.block.factory.Comparators, .Predicates2, org.eclipse.collections.impl.list.mutable.FastList, org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet, org.eclipse.collections.impl.tuple.ImmutableEntry, org.eclipse.collections.impl.utility.ArrayIterate, .Iterate, .MapIterate

See Also
ImmutableSortedMap

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
protected class

Field Summary

Modifier and TypeField and Description
private final Comparator<? super K>
private final K[]
private final V[]

Constructor Summary

AccessConstructor and Description
public
ImmutableTreeMap(SortedMap<K, V> sortedMap)

Method Summary

Modifier and TypeMethod and Description
public Comparator<? super K>
comparator()

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.comparator, java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

public boolean
containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public ImmutableSortedMap<K, V>
drop(int count)

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.drop.

Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.

public Set<Map.Entry<K, V>>
entrySet()

Implements java.util.SortedMap.entrySet.

Returns a Set view of the mappings contained in this map.

public boolean
public K
firstKey()

Implements java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

public ImmutableMap<V, K>
flipUniqueValues()

Implements org.eclipse.collections.api.map.MapIterable.flipUniqueValues, org.eclipse.collections.api.map.ImmutableMapIterable.flipUniqueValues.

Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.

public void
forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure with each key-value pair of the map.

public V
get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public int
public Set<K>
keySet()

Implements java.util.SortedMap.keySet.

Returns a Set view of the keys contained in this map.

public RichIterable<K>
keysView()

Implements org.eclipse.collections.api.map.MapIterable.keysView.

Returns an unmodifiable lazy iterable wrapped around the keySet for the map.

public RichIterable<Pair<K, V>>
keyValuesView()

Implements org.eclipse.collections.api.map.MapIterable.keyValuesView.

Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map.

public K
lastKey()

Implements java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

public static <K, V> ImmutableSortedMap<K, V>
newMap(SortedMap<K, V> sortedMap)

public int
size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Map.size.

Returns the number of items in this iterable.

public ImmutableSortedMap<K, V>
take(int count)

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.take.

Returns the first count elements of the iterable or all the elements in the iterable if count is greater than the length of the iterable.

public String
toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces.

public Collection<V>
values()

Implements java.util.SortedMap.values.

Returns a Collection view of the values contained in this map.

public RichIterable<V>
valuesView()

Implements org.eclipse.collections.api.map.MapIterable.valuesView.

Returns an unmodifiable lazy iterable wrapped around the values for the map.

protected Object
Inherited from org.eclipse.collections.impl.map.sorted.immutable.AbstractImmutableSortedMap:
aggregateBycastToMapcastToSortedMapclearcollectcollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectKeysUniquecollectLongcollectShortcollectValuescollectWithcorrespondscountBycountByEachcountByWithdetectdetectIndexdetectLastIndexdetectOptionaldistinctdropWhileflatCollectflipforEachforEachforEachWithIndexgroupBygroupByEachgroupByUniqueKeyheadMapiteratornewWithAllKeyValueArgumentsnewWithAllKeyValuesnewWithKeyValuenewWithMapnewWithMapIterablenewWithoutAllKeysnewWithoutKeypartitionpartitionWhilepartitionWithputputAllrejectrejectrejectWithremoveselectselectselectInstancesOfselectWithsubMapsumByDoublesumByFloatsumByIntsumByLongtailMaptakeWhiletaptoImmutabletoReversedtoSortedMaptoStackzipzipWithIndex

Field Detail

comparatorback to summary
private final Comparator<? super K> comparator
keysback to summary
private final K[] keys
valuesback to summary
private final V[] values

Constructor Detail

ImmutableTreeMapback to summary
public ImmutableTreeMap(SortedMap<K, V> sortedMap)

Method Detail

comparatorback to summary
public Comparator<? super K> comparator()

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.comparator, java.util.SortedMap.comparator.

Doc from java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

Doc from java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Doc from java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Annotations
@Override
dropback to summary
public ImmutableSortedMap<K, V> drop(int count)

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.drop.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.drop.

Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Implements java.util.SortedMap.entrySet.

Doc from java.util.SortedMap.entrySet.

Returns a Set view of the mappings contained in this map. The set's iterator returns the entries in ascending key order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Implements org.eclipse.collections.api.map.MapIterable.equals, java.util.Map.equals.

Doc from org.eclipse.collections.api.map.MapIterable.equals.

Follows the same general contract as Map#equals(Object).

Annotations
@Override
firstKeyback to summary
public K firstKey()

Implements java.util.SortedMap.firstKey.

Doc from java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

Annotations
@Override
flipUniqueValuesback to summary
public ImmutableMap<V, K> flipUniqueValues()

Implements org.eclipse.collections.api.map.MapIterable.flipUniqueValues, org.eclipse.collections.api.map.ImmutableMapIterable.flipUniqueValues.

Doc from org.eclipse.collections.api.map.MapIterable.flipUniqueValues.

Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.

    MapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
    MapIterable<String, Integer> result = map.flipUniqueValues();
    Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
Annotations
@Override
forEachKeyValueback to summary
public void forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Doc from org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure with each key-value pair of the map.

    final Collection<String> collection = new ArrayList<String>();
    MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
    map.forEachKeyValue((Integer key, String value) -> collection.add(String.valueOf(key) + value));
    Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
Annotations
@Override
getback to summary
public V get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, java.util.Map.get.

Doc from java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements org.eclipse.collections.api.map.MapIterable.hashCode, java.util.Map.hashCode.

Doc from org.eclipse.collections.api.map.MapIterable.hashCode.

Follows the same general contract as Map#hashCode().

Annotations
@Override
keySetback to summary
public Set<K> keySet()

Implements java.util.SortedMap.keySet.

Doc from java.util.SortedMap.keySet.

Returns a Set view of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Annotations
@Override
keysViewback to summary
public RichIterable<K> keysView()

Implements org.eclipse.collections.api.map.MapIterable.keysView.

Doc from org.eclipse.collections.api.map.MapIterable.keysView.

Returns an unmodifiable lazy iterable wrapped around the keySet for the map.

Annotations
@Override
keyValuesViewback to summary
public RichIterable<Pair<K, V>> keyValuesView()

Implements org.eclipse.collections.api.map.MapIterable.keyValuesView.

Doc from org.eclipse.collections.api.map.MapIterable.keyValuesView.

Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map.

Annotations
@Override
lastKeyback to summary
public K lastKey()

Implements java.util.SortedMap.lastKey.

Doc from java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

Annotations
@Override
newMapback to summary
public static <K, V> ImmutableSortedMap<K, V> newMap(SortedMap<K, V> sortedMap)
sizeback to summary
public int size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Map.size.

Doc from org.eclipse.collections.api.RichIterable.size.

Returns the number of items in this iterable.

Annotations
@Override
takeback to summary
public ImmutableSortedMap<K, V> take(int count)

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.take.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.take.

Returns the first count elements of the iterable or all the elements in the iterable if count is greater than the length of the iterable.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Doc from org.eclipse.collections.api.map.MapIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces. Each key and value is separated by an equals sign.

Assert.assertEquals("{1=1, 2=2, 3=3}", Maps.mutable.with(1, 1, 2, 2, 3, 3).toString());
Annotations
@Override
valuesback to summary
public Collection<V> values()

Implements java.util.SortedMap.values.

Doc from java.util.SortedMap.values.

Returns a Collection view of the values contained in this map. The collection's iterator returns the values in ascending order of the corresponding keys. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Annotations
@Override
valuesViewback to summary
public RichIterable<V> valuesView()

Implements org.eclipse.collections.api.map.MapIterable.valuesView.

Doc from org.eclipse.collections.api.map.MapIterable.valuesView.

Returns an unmodifiable lazy iterable wrapped around the values for the map.

Annotations
@Override
writeReplaceback to summary
protected Object writeReplace()
org.eclipse.collections.impl.map.sorted.immutable back to summary

private final Class ImmutableTreeMap.EntryComparator<K, V>

extends Object
implements Comparator<Map.Entry<K, V>>
Class Inheritance
  • java.lang.Object
  • org.eclipse.collections.impl.map.sorted.immutable.ImmutableTreeMap.EntryComparator
All Implemented Interfaces
java.util.Comparator

Field Summary

Modifier and TypeField and Description
private final Comparator<? super K>

Constructor Summary

AccessConstructor and Description
private
EntryComparator(Comparator<? super K> comparator)

Method Summary

Modifier and TypeMethod and Description
public int
compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

comparatorback to summary
private final Comparator<? super K> comparator

Constructor Detail

EntryComparatorback to summary
private EntryComparator(Comparator<? super K> comparator)

Method Detail

compareback to summary
public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Annotations
@Override
org.eclipse.collections.impl.map.sorted.immutable back to summary

protected Class ImmutableTreeMap.ImmutableSortedMapKeySet

extends AbstractSet<K>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean
add(K key)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present (optional operation).

public boolean
addAll(Collection<? extends K> collection)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.Set.addAll, java.util.Collection.addAll.

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

public void
clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Removes all of the elements from this set (optional operation).

public boolean
contains(Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Returns true if this set contains the specified element.

public boolean
containsAll(Collection<?> collection)

Overrides java.util.AbstractCollection.containsAll.

Implements java.util.Set.containsAll, java.util.Collection.containsAll.

Returns true if this set contains all of the elements of the specified collection.

public Iterator<K>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.

public boolean
remove(Object key)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Removes the specified element from this set if it is present (optional operation).

public boolean
removeAll(Collection<?> collection)

Overrides java.util.AbstractSet.removeAll.

Implements java.util.Set.removeAll, java.util.Collection.removeAll.

Removes from this set all of its elements that are contained in the specified collection (optional operation).

public boolean
retainAll(Collection<?> collection)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.Set.retainAll, java.util.Collection.retainAll.

Retains only the elements in this set that are contained in the specified collection (optional operation).

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).

public Object[]
toArray()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Returns an array containing all of the elements in this set.

public <T> T[]
toArray(T[] a)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

protected Object
Inherited from java.util.AbstractSet:
equalshashCode

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ImmutableSortedMapKeySetback to summary
protected ImmutableSortedMapKeySet()

Method Detail

addback to summary
public boolean add(K key)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Doc from java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throw an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

Annotations
@Override
addAllback to summary
public boolean addAll(Collection<? extends K> collection)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.Set.addAll, java.util.Collection.addAll.

Doc from java.util.Set.addAll.

Adds all of the elements in the specified collection to this set if they're not already present (optional operation). If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Annotations
@Override
clearback to summary
public void clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Doc from java.util.Set.clear.

Removes all of the elements from this set (optional operation). The set will be empty after this call returns.

Annotations
@Override
containsback to summary
public boolean contains(Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Doc from java.util.Set.contains.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

Annotations
@Override
containsAllback to summary
public boolean containsAll(Collection<?> collection)

Overrides java.util.AbstractCollection.containsAll.

Implements java.util.Set.containsAll, java.util.Collection.containsAll.

Doc from java.util.Set.containsAll.

Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set.

Annotations
@Override
iteratorback to summary
public Iterator<K> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Annotations
@Override
removeback to summary
public boolean remove(Object key)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Doc from java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)

Annotations
@Override
removeAllback to summary
public boolean removeAll(Collection<?> collection)

Overrides java.util.AbstractSet.removeAll.

Implements java.util.Set.removeAll, java.util.Collection.removeAll.

Doc from java.util.AbstractSet.removeAll.

Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.

This implementation determines which is the smaller of this set and the specified collection, by invoking the size method on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is so contained, it is removed from this set with the iterator's remove method. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this set's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method.

Annotations
@Override
retainAllback to summary
public boolean retainAll(Collection<?> collection)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.Set.retainAll, java.util.Collection.retainAll.

Doc from java.util.Set.retainAll.

Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
toArrayback to summary
public Object[] toArray()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Doc from java.util.Set.toArray.

Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Annotations
@Override
toArrayback to summary
public <T> T[] toArray(T[] a)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Doc from java.util.Set.toArray.

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.

If this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set to null. (This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements.)

If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose x is a set known to contain only strings. The following code can be used to dump the set into a newly allocated array of String:

    String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
Annotations
@Override
writeReplaceback to summary
protected Object writeReplace()