Class java.util.Collections.SynchronizedList
java.lang.Object
|
+--java.util.Collections.SynchronizedCollection
|
+--java.util.Collections.SynchronizedList
- static class Collections.SynchronizedList
- extends Collections.SynchronizedCollection
- implements List
- See Also:
- Serialized Form
Methods inherited from class java.util.Collections.SynchronizedCollection |
addAll, add, clear, containsAll, contains, isEmpty, iterator, removeAll, remove, retainAll, size, toArray, toArray |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait |
Collections.SynchronizedList
Collections.SynchronizedList(List list)
Collections.SynchronizedList
Collections.SynchronizedList(List list,
java.lang.Object mutex)
equals
public boolean equals(java.lang.Object o)
- Description copied from interface:
Compares the specified Object with this List for equality. Returns true
if and only if the specified Object is also a List, both Lists have the
same size, and all corresponding pairs of elements in the two Lists are
equal. (Two elements e1
and e2
are
equal if (e1==null ? e2==null : e1.equals(e2))
.)
In other words, two Lists are defined to be equal if they contain the
same elements in the same order.
- Specified by:
- equals in interface List
- Overrides:
- equals in class java.lang.Object
hashCode
public int hashCode()
- Description copied from interface:
Returns the hash code value for this List. The hash code of a List
is defined to be the result of the following calculation:
hashCode = 1;
Iterator i = list.iterator();
while (i.hasNext()) {
Object obj = i.next();
hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
}
This ensures that list1.equals(list2)
implies that
list1.hashCode()==list2.hashCode()
for any two Lists,
list1
and list2
, as required by the general
contract of Object.hashCode.
- Specified by:
- hashCode in interface List
- Overrides:
- hashCode in class java.lang.Object
get
public java.lang.Object get(int index)
- Description copied from interface:
Returns the element at the specified position in this List.
- Specified by:
- get in interface List
set
public java.lang.Object set(int index,
java.lang.Object element)
- Description copied from interface:
Replaces the element at the specified position in this List with the
specified element (optional operation).
- Specified by:
- set in interface List
add
public void add(int index,
java.lang.Object element)
- Description copied from interface:
Inserts the specified element at the specified position in this List
(optional operation). Shifts the element currently at that position
(if any) and any subsequent elements to the right (adds one to their
indices).
- Specified by:
- add in interface List
remove
public java.lang.Object remove(int index)
- Description copied from interface:
Removes the element at the specified position in this List (optional
operation). Shifts any subsequent elements to the left (subtracts one
from their indices). Returns the element that was removed from the
List.
- Specified by:
- remove in interface List
indexOf
public int indexOf(java.lang.Object o)
- Description copied from interface:
Returns the index in this List of the first occurrence of the specified
element, or -1 if the List does not contain this element.
More formally, returns the lowest index i such that
(o==null ? get(i)==null : o.equals(get(i)))
,
or -1 if there is no such index.
- Specified by:
- indexOf in interface List
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Description copied from interface:
Returns the index in this List of the last occurrence of the specified
element, or -1 if the List does not contain this element.
More formally, returns the highest index i such that
(o==null ? get(i)==null : o.equals(get(i)))
,
or -1 if there is no such index.
- Specified by:
- lastIndexOf in interface List
addAll
public boolean addAll(int index,
Collection c)
- Description copied from interface:
Inserts all of the elements in the specified Collection into this
List at the specified position (optional operation). Shifts the
element currently at that position (if any) and any subsequent
elements to the right (increases their indices). The new elements
will appear in the List in the order that they are returned by the
specified Collection's iterator. The behavior of this operation is
unspecified if the specified Collection is modified while the
operation is in progress. (Note that this will occur if the specified
Collection is this List, and it's nonempty.)
- Specified by:
- addAll in interface List
listIterator
public ListIterator listIterator()
- Description copied from interface:
Returns a ListIterator of the elements in this List (in proper
sequence).
- Specified by:
- listIterator in interface List
listIterator
public ListIterator listIterator(int index)
- Description copied from interface:
Returns a ListIterator of the elements in this List (in proper
sequence), starting at the specified position in the List. The
specified index indicates the first element that would be returned by
an initial call to nextElement. An initial call to previousElement
would return the element with the specified index minus one.
- Specified by:
- listIterator in interface List
subList
public List subList(int fromIndex,
int toIndex)
- Description copied from interface:
Returns a view of the portion of this List between fromIndex,
inclusive, and toIndex, exclusive. The returned List is backed by this
List, so changes in the returned List are reflected in this List, and
vice-versa. The returned List supports all of the optional List
operations supported by this List.
This method eliminates the need for explicit range operations (of
the sort that commonly exist for arrays). Any operation that expects
a List can be used as a range operation by passing a subList view
instead of a whole List. For example, the following idiom
removes a range of elements from a List:
list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf.
The semantics of the List returned by this method become undefined if
the backing list (i.e., this List) is structurally modified in
any way other than via the returned List. (Structural modifications are
those that change the size of the List, or otherwise perturb it in such
a fashion that iterations in progress may yield incorrect results.)
- Specified by:
- subList in interface List