public class UnmodifiableList<E> extends UnmodifiableCollection<E> implements java.util.List<E>
List prohibiting all calls which would modify
its contents. As the construction of this class is performed in constant time
it is preferred over copying the list (which takes linear time). Using this
class is also preferred to using the unmodifiableX() in class
Collections as they return the collection base type that does not
signal that the object is unmodifiable. Using the classes in this package
makes unmodifiability more explicit.
All prohibited methods throw an UnsupportedOperationException. The
class is nearly the same as the one returned by
Collections.unmodifiableList(List), but by making it a public class
we can make the return value of some methods more explicit.
This list is serializable if the wrapped list is serializable.
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<E> |
l
The underlying list.
|
| Constructor and Description |
|---|
UnmodifiableList(java.util.List<E> l)
Creates a new unmodifiable list from another list.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int arg0,
E arg1)
Operation is not supported.
|
boolean |
addAll(int arg0,
java.util.Collection<? extends E> arg1)
Operation is not supported.
|
E |
get(int index) |
int |
indexOf(java.lang.Object o) |
int |
lastIndexOf(java.lang.Object o) |
UnmodifiableListIterator<E> |
listIterator() |
UnmodifiableListIterator<E> |
listIterator(int index) |
E |
remove(int arg0)
Operation is not supported.
|
E |
set(int arg0,
E arg1)
Operation is not supported.
|
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitpublic UnmodifiableList(java.util.List<E> l)
public int lastIndexOf(java.lang.Object o)
lastIndexOf in interface java.util.List<E>public UnmodifiableListIterator<E> listIterator()
listIterator in interface java.util.List<E>public UnmodifiableListIterator<E> listIterator(int index)
listIterator in interface java.util.List<E>public java.util.List<E> subList(int fromIndex, int toIndex)
subList in interface java.util.List<E>public void add(int arg0, E arg1)
add in interface java.util.List<E>public boolean addAll(int arg0, java.util.Collection<? extends E> arg1)
addAll in interface java.util.List<E>public E remove(int arg0)
remove in interface java.util.List<E>