◆java.util.*; ** ・ Collections.unmodifiableXXX ([List and Map instances]); **
//If it is only final, it cannot be reassigned, but elements can be added / deleted.
//Unmodifiable XXX disables element modification.
//If you try to change it, an "UnsupportedOperationException" will be thrown.
//List (Do not add a semicolon at the end of the instance initializer line)
private static final List<String> LIST_1 = Collections.unmodifiableList( new ArrayList<String>() {{ add("X"); add("Y"); }} );
//Map
private static final Map<Integer, String> MAP_1 = Collections.unmodifiableMap( new HashMap<Integer, String>() {{ put(1, "X"); put(2, "Y"); }} );
Method name | Description |
---|---|
boolean add(E e) | Add the argument element to the collection. Returns true if the collection has changed as a result of this call |
void add(int index, E element) | Adds an element at the specified position. If there are elements at that position and after that, move them and add 1 to the index of each element. |
void clear() | Remove all elements from this collection |
boolean contains(Object obj) | Returns true if the specified element obj exists in this collection |
boolean containsAll(Collection<?> c) | Returns true if all elements of the specified collection are contained in this collection |
boolean isEmpty() | Returns true if this collection contains no elements |
boolean remove(Object o) | Deletes the element specified in the argument and returns true if the element is deleted |
boolean removeAll(Collection<?> c) | Removes all elements from the collection specified in the method argument from this collection and returns true if the contents of this collection have changed as a result of calling this method. |
Iterator |
Returns an iterator for the elements of this collection |
Object[] toArray() | Returns an array containing all the elements of this collection |
Returns an array containing all the elements of this collection. T returns the data type of the array element | |
int size() | Returns the number of elements in the collection |
Method name | Description |
Method name | Description |
Recommended Posts