Schnittstelle UnmodifiableCollection<E>
- Alle Superschnittstellen:
Iterable<E>
- Alle bekannten Unterschnittstellen:
UnmodifiableList<E>
- Alle bekannten Implementierungsklassen:
UnmodifiableListAdapter
- Autor:
- Mirko Klemm 2015-03-15
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungbooleanReturns true if this collection contains the specified element.booleancontainsAll(Collection<?> c) Returns true if this collection contains all of the elements in the specified collection.booleanisEmpty()Returns true if this collection contains no elements.iterator()Returns an iterator over the elements in this collection.intsize()Returns the number of elements in this collection.Object[]toArray()Returns an array containing all of the elements in this collection.<T> T[]toArray(T[] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.Von Schnittstelle geerbte Methoden java.lang.Iterable
forEach, spliterator
-
Methodendetails
-
size
int size()Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.- Gibt zurück:
- the number of elements in this collection
-
isEmpty
boolean isEmpty()Returns true if this collection contains no elements.- Gibt zurück:
- true if this collection contains no elements
-
contains
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).- Parameter:
o- element whose presence in this collection is to be tested- Gibt zurück:
- true if this collection contains the specified element
- Löst aus:
ClassCastException- if the type of the specified element is incompatible with this collection (optional)NullPointerException- if the specified element is null and this collection does not permit null elements (optional)
-
iterator
Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee). -
toArray
Object[] toArray()Returns an array containing all of the elements in this collection. If this collection 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 collection. (In other words, this method must allocate a new array even if this collection 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.
- Gibt zurück:
- an array containing all of the elements in this collection
-
toArray
<T> T[] toArray(T[] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection 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 collection.If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)
If this collection 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 collection known to contain only strings. The following code can be used to dump the collection 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().- Parameter:
a- the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Gibt zurück:
- an array containing all of the elements in this collection
- Löst aus:
ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type of every element in this collectionNullPointerException- if the specified array is null
-
containsAll
Returns true if this collection contains all of the elements in the specified collection.- Parameter:
c- collection to be checked for containment in this collection- Gibt zurück:
- true if this collection contains all of the elements in the specified collection
- Löst aus:
ClassCastException- if the types of one or more elements in the specified collection are incompatible with this collection (optional)NullPointerException- if the specified collection contains one or more null elements and this collection does not permit null elements (optional), or if the specified collection is null.- Siehe auch:
-