jdk/src/share/classes/java/util/List.java
author akhil
Mon, 22 Apr 2013 09:19:34 -0700
changeset 17166 c83a0fa44906
parent 16929 c984ae5655cb
child 19074 84a8d23e8f32
permissions -rw-r--r--
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort Reviewed-by: alanb, dholmes, mduigou, psandoz, smarks Contributed-by: Akhil Arora <akhil.arora@oracle.com>, Arne Siegel <v.a.ammodytes@googlemail.com>, Brian Goetz <brian.goetz@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
17166
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
    28
import java.util.function.UnaryOperator;
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An ordered collection (also known as a <i>sequence</i>).  The user of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * interface has precise control over where in the list each element is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * inserted.  The user can access elements by their integer index (position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the list), and search for elements in the list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Unlike sets, lists typically allow duplicate elements.  More formally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * such that <tt>e1.equals(e2)</tt>, and they typically allow multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * null elements if they allow null elements at all.  It is not inconceivable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * that someone might wish to implement a list that prohibits duplicates, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * throwing runtime exceptions when the user attempts to insert them, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * expect this usage to be rare.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The <tt>List</tt> interface places additional stipulations, beyond those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * specified in the <tt>Collection</tt> interface, on the contracts of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <tt>iterator</tt>, <tt>add</tt>, <tt>remove</tt>, <tt>equals</tt>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * also included here for convenience.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The <tt>List</tt> interface provides four methods for positional (indexed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * access to list elements.  Lists (like Java arrays) are zero based.  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * that these operations may execute in time proportional to the index value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * for some implementations (the <tt>LinkedList</tt> class, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * example). Thus, iterating over the elements in a list is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * preferable to indexing through it if the caller does not know the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * implementation.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * The <tt>List</tt> interface provides a special iterator, called a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <tt>ListIterator</tt>, that allows element insertion and replacement, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * bidirectional access in addition to the normal operations that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <tt>Iterator</tt> interface provides.  A method is provided to obtain a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * list iterator that starts at a specified position in the list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The <tt>List</tt> interface provides two methods to search for a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * object.  From a performance standpoint, these methods should be used with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * caution.  In many implementations they will perform costly linear
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * searches.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * The <tt>List</tt> interface provides two methods to efficiently insert and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * remove multiple elements at an arbitrary point in the list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Note: While it is permissible for lists to contain themselves as elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * extreme caution is advised: the <tt>equals</tt> and <tt>hashCode</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * methods are no longer well defined on such a list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>Some list implementations have restrictions on the elements that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * they may contain.  For example, some implementations prohibit null elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * and some have restrictions on the types of their elements.  Attempting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * add an ineligible element throws an unchecked exception, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * to query the presence of an ineligible element may throw an exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * or it may simply return false; some implementations will exhibit the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * behavior and some will exhibit the latter.  More generally, attempting an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * operation on an ineligible element whose completion would not result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the insertion of an ineligible element into the list may throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * exception or it may succeed, at the option of the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Such exceptions are marked as "optional" in the specification for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
4977
81902a400bbf 6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents: 2
diff changeset
    94
 * @param <E> the type of elements in this list
81902a400bbf 6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents: 2
diff changeset
    95
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @author  Neal Gafter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @see Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see ArrayList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see LinkedList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @see Vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @see Arrays#asList(Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @see Collections#nCopies(int, Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @see Collections#EMPTY_LIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * @see AbstractList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * @see AbstractSequentialList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
public interface List<E> extends Collection<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // Query Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns the number of elements in this list.  If this list contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * more than <tt>Integer.MAX_VALUE</tt> elements, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <tt>Integer.MAX_VALUE</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return the number of elements in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    int size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns <tt>true</tt> if this list contains no elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return <tt>true</tt> if this list contains no elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    boolean isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns <tt>true</tt> if this list contains the specified element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * More formally, returns <tt>true</tt> if and only if this list contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * at least one element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param o element whose presence in this list is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return <tt>true</tt> if this list contains the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   139
     *         is incompatible with this list
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   140
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   142
     *         list does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   143
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Returns an iterator over the elements in this list in proper sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return an iterator over the elements in this list in proper sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Returns an array containing all of the elements in this list in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * sequence (from first to last element).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <p>The returned array will be "safe" in that no references to it are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * maintained by this list.  (In other words, this method must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * allocate a new array even if this list is backed by an array).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * The caller is thus free to modify the returned array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <p>This method acts as bridge between array-based and collection-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @return an array containing all of the elements in this list in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *         sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @see Arrays#asList(Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    Object[] toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Returns an array containing all of the elements in this list in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * proper sequence (from first to last element); the runtime type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * the returned array is that of the specified array.  If the list fits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * in the specified array, it is returned therein.  Otherwise, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * array is allocated with the runtime type of the specified array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * the size of this list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <p>If the list fits in the specified array with room to spare (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * the array has more elements than the list), the element in the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * immediately following the end of the list is set to <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * (This is useful in determining the length of the list <i>only</i> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * the caller knows that the list does not contain any null elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <p>Like the {@link #toArray()} method, this method acts as bridge between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * array-based and collection-based APIs.  Further, this method allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * precise control over the runtime type of the output array, and may,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * under certain circumstances, be used to save allocation costs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * The following code can be used to dump the list into a newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * allocated array of <tt>String</tt>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *     String[] y = x.toArray(new String[0]);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <tt>toArray()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param a the array into which the elements of this list are to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *          be stored, if it is big enough; otherwise, a new array of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *          same runtime type is allocated for this purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return an array containing the elements of this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @throws ArrayStoreException if the runtime type of the specified array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *         is not a supertype of the runtime type of every element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *         this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @throws NullPointerException if the specified array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    <T> T[] toArray(T[] a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Appends the specified element to the end of this list (optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p>Lists that support this operation may place limitations on what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * elements may be added to this list.  In particular, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * lists will refuse to add null elements, and others will impose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * restrictions on the type of elements that may be added.  List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * classes should clearly specify in their documentation any restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * on what elements may be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param e element to be appended to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return <tt>true</tt> (as specified by {@link Collection#add})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *         list does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws IllegalArgumentException if some property of this element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Removes the first occurrence of the specified element from this list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * if it is present (optional operation).  If this list does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * the element, it is unchanged.  More formally, removes the element with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * the lowest index <tt>i</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * (if such an element exists).  Returns <tt>true</tt> if this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * contained the specified element (or equivalently, if this list changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param o element to be removed from this list, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return <tt>true</tt> if this list contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   252
     *         is incompatible with this list
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   253
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   255
     *         list does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   256
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // Bulk Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Returns <tt>true</tt> if this list contains all of the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param  c collection to be checked for containment in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @return <tt>true</tt> if this list contains all of the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *         specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *         in the specified collection are incompatible with this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   274
     *         list
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   275
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *         or more null elements and this list does not permit null
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   278
     *         elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   279
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   280
     *         or if the specified collection is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    boolean containsAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Appends all of the elements in the specified collection to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * this list, in the order that they are returned by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * collection's iterator (optional operation).  The behavior of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * operation is undefined if the specified collection is modified while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * the operation is in progress.  (Note that this will occur if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * specified collection is this list, and it's nonempty.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param c collection containing elements to be added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @return <tt>true</tt> if this list changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @throws ClassCastException if the class of an element of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *         collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *         or more null elements and this list does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *         elements, or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *         specified collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see #add(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    boolean addAll(Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Inserts all of the elements in the specified collection into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * list at the specified position (optional operation).  Shifts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * element currently at that position (if any) and any subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * elements to the right (increases their indices).  The new elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * will appear in this list in the order that they are returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * specified collection's iterator.  The behavior of this operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * undefined if the specified collection is modified while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * operation is in progress.  (Note that this will occur if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * collection is this list, and it's nonempty.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param index index at which to insert the first element from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *              specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param c collection containing elements to be added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return <tt>true</tt> if this list changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @throws ClassCastException if the class of an element of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *         collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *         or more null elements and this list does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *         elements, or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *         specified collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    boolean addAll(int index, Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * Removes from this list all of its elements that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * specified collection (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @param c collection containing elements to be removed from this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return <tt>true</tt> if this list changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @throws ClassCastException if the class of an element of this list
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   346
     *         is incompatible with the specified collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   347
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @throws NullPointerException if this list contains a null element and the
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   349
     *         specified collection does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   350
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    boolean removeAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Retains only the elements in this list that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * specified collection (optional operation).  In other words, removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * from this list all of its elements that are not contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param c collection containing elements to be retained in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @return <tt>true</tt> if this list changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @throws ClassCastException if the class of an element of this list
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   368
     *         is incompatible with the specified collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   369
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @throws NullPointerException if this list contains a null element and the
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   371
     *         specified collection does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   372
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    boolean retainAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
17166
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   380
     * Replaces each element of this list with the result of applying the
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   381
     * operator to that element.  Errors or runtime exceptions thrown by
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   382
     * the operator are relayed to the caller.
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   383
     *
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   384
     * @implSpec
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   385
     * The default implementation is equivalent to, for this {@code list}:
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   386
     * <pre>
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   387
     * final ListIterator<E> li = list.listIterator();
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   388
     * while (li.hasNext()) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   389
     *   li.set(operator.apply(li.next()));
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   390
     * }
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   391
     * </pre>
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   392
     * If the list's list-iterator does not support the {@code set} operation
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   393
     * then an {@code UnsupportedOperationException} will be thrown when
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   394
     * replacing the first element.
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   395
     *
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   396
     * @param operator the operator to apply to each element
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   397
     * @throws UnsupportedOperationException if the {@code set}
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   398
     *         operation is not supported by this list
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   399
     * @throws NullPointerException if the specified operator is null or
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   400
     *         if the element is replaced with a null value and this list
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   401
     *         does not permit null elements
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   402
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   403
     * @since 1.8
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   404
     */
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   405
    default void replaceAll(UnaryOperator<E> operator) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   406
        Objects.requireNonNull(operator);
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   407
        final ListIterator<E> li = this.listIterator();
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   408
        while (li.hasNext()) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   409
            li.set(operator.apply(li.next()));
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   410
        }
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   411
    }
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   412
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   413
    /**
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   414
     * Sorts this list using the supplied {@code Comparator} to compare elements.
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   415
     *
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   416
     * @implSpec
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   417
     * The default implementation is equivalent to, for this {@code list}:
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   418
     * <pre>Collections.sort(list, c)</pre>
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   419
     *
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   420
     * @param c the {@code Comparator} used to compare list elements.
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   421
     *          A {@code null} value indicates that the elements'
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   422
     *          {@linkplain Comparable natural ordering} should be used
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   423
     * @throws ClassCastException if the list contains elements that are not
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   424
     *         <i>mutually comparable</i> using the specified comparator
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   425
     * @throws UnsupportedOperationException if the list's list-iterator does
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   426
     *         not support the {@code set} operation
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   427
     * @throws IllegalArgumentException
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   428
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   429
     *         if the comparator is found to violate the {@link Comparator}
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   430
     *         contract
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   431
     * @since 1.8
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   432
     */
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   433
    default void sort(Comparator<? super E> c) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   434
        Collections.sort(this, c);
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   435
    }
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   436
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   437
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Removes all of the elements from this list (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * The list will be empty after this call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    void clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // Comparison and hashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Compares the specified object with this list for equality.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * <tt>true</tt> if and only if the specified object is also a list, both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * lists have the same size, and all corresponding pairs of elements in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * the two lists are <i>equal</i>.  (Two elements <tt>e1</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * e1.equals(e2))</tt>.)  In other words, two lists are defined to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * equal if they contain the same elements in the same order.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * definition ensures that the equals method works properly across
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * different implementations of the <tt>List</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param o the object to be compared for equality with this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @return <tt>true</tt> if the specified object is equal to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Returns the hash code value for this list.  The hash code of a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * is defined to be the result of the following calculation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *  int hashCode = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *  for (E e : list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *      hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * This ensures that <tt>list1.equals(list2)</tt> implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * <tt>list1.hashCode()==list2.hashCode()</tt> for any two lists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <tt>list1</tt> and <tt>list2</tt>, as required by the general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * contract of {@link Object#hashCode}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @return the hash code value for this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see #equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    // Positional Access Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Returns the element at the specified position in this list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param index index of the element to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @return the element at the specified position in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    E get(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Replaces the element at the specified position in this list with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * specified element (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @param index index of the element to replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @param element element to be stored at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @return the element previously at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @throws UnsupportedOperationException if the <tt>set</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @throws NullPointerException if the specified element is null and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *         this list does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *         element prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    E set(int index, E element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Inserts the specified element at the specified position in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * (optional operation).  Shifts the element currently at that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * (if any) and any subsequent elements to the right (adds one to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * indices).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param index index at which the specified element is to be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @param element element to be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @throws NullPointerException if the specified element is null and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *         this list does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *         element prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    void add(int index, E element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Removes the element at the specified position in this list (optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * operation).  Shifts any subsequent elements to the left (subtracts one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * from their indices).  Returns the element that was removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @param index the index of the element to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @return the element previously at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    E remove(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    // Search Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * Returns the index of the first occurrence of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * in this list, or -1 if this list does not contain the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * More formally, returns the lowest index <tt>i</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * or -1 if there is no such index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @param o element to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @return the index of the first occurrence of the specified element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *         this list, or -1 if this list does not contain the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   567
     *         is incompatible with this list
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   568
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   570
     *         list does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   571
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    int indexOf(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Returns the index of the last occurrence of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * in this list, or -1 if this list does not contain the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * More formally, returns the highest index <tt>i</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * or -1 if there is no such index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @param o element to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @return the index of the last occurrence of the specified element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *         this list, or -1 if this list does not contain the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   586
     *         is incompatible with this list
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   587
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   589
     *         list does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   590
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    int lastIndexOf(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    // List Iterators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Returns a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * sequence).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @return a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *         sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    ListIterator<E> listIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Returns a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * sequence), starting at the specified position in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * The specified index indicates the first element that would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * returned by an initial call to {@link ListIterator#next next}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * An initial call to {@link ListIterator#previous previous} would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * return the element with the specified index minus one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @param index index of the first element to be returned from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *        list iterator (by a call to {@link ListIterator#next next})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @return a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *         sequence), starting at the specified position in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *         ({@code index < 0 || index > size()})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    ListIterator<E> listIterator(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    // View
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Returns a view of the portion of this list between the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.  (If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * empty.)  The returned list is backed by this list, so non-structural
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * changes in the returned list are reflected in this list, and vice-versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * The returned list supports all of the optional list operations supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * by this list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * This method eliminates the need for explicit range operations (of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * the sort that commonly exist for arrays).  Any operation that expects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * a list can be used as a range operation by passing a subList view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * instead of a whole list.  For example, the following idiom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * removes a range of elements from a list:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *      list.subList(from, to).clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Similar idioms may be constructed for <tt>indexOf</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <tt>lastIndexOf</tt>, and all of the algorithms in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <tt>Collections</tt> class can be applied to a subList.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * The semantics of the list returned by this method become undefined if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * the backing list (i.e., this list) is <i>structurally modified</i> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * any way other than via the returned list.  (Structural modifications are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * those that change the size of this list, or otherwise perturb it in such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * a fashion that iterations in progress may yield incorrect results.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @param fromIndex low endpoint (inclusive) of the subList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param toIndex high endpoint (exclusive) of the subList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return a view of the specified range within this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @throws IndexOutOfBoundsException for an illegal endpoint index value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *         (<tt>fromIndex &lt; 0 || toIndex &gt; size ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *         fromIndex &gt; toIndex</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    List<E> subList(int fromIndex, int toIndex);
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   660
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   661
    /**
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   662
     * Creates a {@link Spliterator} over the elements in this list.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   663
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   664
     * <p>The {@code Spliterator} reports {@link Spliterator#SIZED} and
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   665
     * {@link Spliterator#ORDERED}.  Implementations should document the
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   666
     * reporting of additional characteristic values.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   667
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   668
     * @implSpec
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   669
     * The default implementation creates a
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   670
     * <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   671
     * from the list's {@code Iterator}.  The spliterator inherits the
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   672
     * <em>fail-fast</em> properties of the collection's iterator.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   673
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   674
     * @implNote
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   675
     * The created {@code Spliterator} additionally reports
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   676
     * {@link Spliterator#SUBSIZED}.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   677
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   678
     * @return a {@code Spliterator} over the elements in this list
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   679
     * @since 1.8
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   680
     */
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   681
    @Override
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   682
    default Spliterator<E> spliterator() {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   683
        return Spliterators.spliterator(this, Spliterator.ORDERED);
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   684
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
}
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   686