T
- element type of the underlying array@NotThreadSafe public class UnmodifiableArrayList<T> extends Object implements List<T>
toArray()
.
The difference to Collections.unmodifiableList(Arrays.asList(array))
is,
in some Java implementations like adoptjdk, Arrays.asList() copies the array with
new ArrayList<>(array)
so it is not performant.
Also this class makes it possible to recover the original array from the List,
list.toArray()
returns the underlying array instead of a copy.
Use the underlying array for modification if needed.
Use this when you just want to return an unmodifiable view of the array.
There is no extra thread safety guarantee on this List.
When the underlying array changes, the view will change too,
and there is no extra thread safety.Constructor and Description |
---|
UnmodifiableArrayList(T[] elements) |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
T element) |
boolean |
add(T t) |
boolean |
addAll(Collection<? extends T> c) |
boolean |
addAll(int index,
Collection<? extends T> c) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
T |
get(int index) |
int |
indexOf(Object o) |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<T> |
listIterator() |
ListIterator<T> |
listIterator(int index) |
T |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
T |
set(int index,
T element) |
int |
size() |
List<T> |
subList(int fromIndex,
int toIndex) |
Object[] |
toArray() |
<T1> T1[] |
toArray(T1[] a) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
equals, hashCode, replaceAll, sort, spliterator
parallelStream, removeIf, stream
public UnmodifiableArrayList(T[] elements)
elements
- the underlying arraypublic int size()
public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T1> T1[] toArray(T1[] a)
public boolean add(T t)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<T>
containsAll
in interface List<T>
public boolean addAll(Collection<? extends T> c)
public boolean addAll(int index, Collection<? extends T> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public int lastIndexOf(Object o)
lastIndexOf
in interface List<T>
public ListIterator<T> listIterator()
listIterator
in interface List<T>
public ListIterator<T> listIterator(int index)
listIterator
in interface List<T>
Copyright © 2023. All Rights Reserved.