jdk/src/share/classes/java/util/Collection.java
author psandoz
Tue, 13 Aug 2013 11:16:37 +0200
changeset 19424 c4524285927f
parent 18829 ec84f0c313b0
child 19850 93b368e54c1c
permissions -rw-r--r--
8022797: Clarify spliterator characteristics for collections containing no elements Reviewed-by: alanb, mduigou
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.Predicate;
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
    29
import java.util.stream.Stream;
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
    30
import java.util.stream.StreamSupport;
17166
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The root interface in the <i>collection hierarchy</i>.  A collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * represents a group of objects, known as its <i>elements</i>.  Some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * collections allow duplicate elements and others do not.  Some are ordered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * and others unordered.  The JDK does not provide any <i>direct</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * implementations of this interface: it provides implementations of more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * specific subinterfaces like <tt>Set</tt> and <tt>List</tt>.  This interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * is typically used to pass collections around and manipulate them where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * maximum generality is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p><i>Bags</i> or <i>multisets</i> (unordered collections that may contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * duplicate elements) should implement this interface directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>All general-purpose <tt>Collection</tt> implementation classes (which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * typically implement <tt>Collection</tt> indirectly through one of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * subinterfaces) should provide two "standard" constructors: a void (no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * arguments) constructor, which creates an empty collection, and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * constructor with a single argument of type <tt>Collection</tt>, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * creates a new collection with the same elements as its argument.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * effect, the latter constructor allows the user to copy any collection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * producing an equivalent collection of the desired implementation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * There is no way to enforce this convention (as interfaces cannot contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * constructors) but all of the general-purpose <tt>Collection</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * implementations in the Java platform libraries comply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>The "destructive" methods contained in this interface, that is, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * methods that modify the collection on which they operate, are specified to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * throw <tt>UnsupportedOperationException</tt> if this collection does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * support the operation.  If this is the case, these methods may, but are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * required to, throw an <tt>UnsupportedOperationException</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * invocation would have no effect on the collection.  For example, invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * the {@link #addAll(Collection)} method on an unmodifiable collection may,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * but is not required to, throw the exception if the collection to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
18829
ec84f0c313b0 8020409: Clean up doclint problems in java.util package, part 1
bpb
parents: 18824
diff changeset
    67
 * <p><a name="optional-restrictions">
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
    68
 * Some collection implementations have restrictions on the elements that
18829
ec84f0c313b0 8020409: Clean up doclint problems in java.util package, part 1
bpb
parents: 18824
diff changeset
    69
 * they may contain.</a>  For example, some implementations prohibit null elements,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * and some have restrictions on the types of their elements.  Attempting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * add an ineligible element throws an unchecked exception, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * to query the presence of an ineligible element may throw an exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * or it may simply return false; some implementations will exhibit the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * behavior and some will exhibit the latter.  More generally, attempting an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * operation on an ineligible element whose completion would not result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * the insertion of an ineligible element into the collection may throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * exception or it may succeed, at the option of the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Such exceptions are marked as "optional" in the specification for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>It is up to each collection to determine its own synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * policy.  In the absence of a stronger guarantee by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * implementation, undefined behavior may result from the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * of any method on a collection that is being mutated by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * thread; this includes direct invocations, passing the collection to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * a method that might perform invocations, and using an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * iterator to examine the collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>Many methods in Collections Framework interfaces are defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * terms of the {@link Object#equals(Object) equals} method.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * the specification for the {@link #contains(Object) contains(Object o)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * method says: "returns <tt>true</tt> if and only if this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * contains at least one element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <tt>(o==null ? e==null : o.equals(e))</tt>."  This specification should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <i>not</i> be construed to imply that invoking <tt>Collection.contains</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * with a non-null argument <tt>o</tt> will cause <tt>o.equals(e)</tt> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * invoked for any element <tt>e</tt>.  Implementations are free to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * optimizations whereby the <tt>equals</tt> invocation is avoided, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * example, by first comparing the hash codes of the two elements.  (The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * {@link Object#hashCode()} specification guarantees that two objects with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * unequal hash codes cannot be equal.)  More generally, implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * the various Collections Framework interfaces are free to take advantage of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * the specified behavior of underlying {@link Object} methods wherever the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * implementor deems it appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   111
 * @implSpec
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   112
 * The default method implementations (inherited or otherwise) do not apply any
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   113
 * synchronization protocol.  If a {@code Collection} implementation has a
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   114
 * specific synchronization protocol, then it must override default
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   115
 * implementations to apply that protocol.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   116
 *
4977
81902a400bbf 6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents: 1818
diff changeset
   117
 * @param <E> the type of elements in this collection
81902a400bbf 6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents: 1818
diff changeset
   118
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @author  Neal Gafter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @see     Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @see     List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see     Map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @see     SortedSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @see     SortedMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @see     HashSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @see     TreeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * @see     ArrayList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @see     LinkedList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @see     Vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @see     Collections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @see     Arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @see     AbstractCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
public interface Collection<E> extends Iterable<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // Query Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Returns the number of elements in this collection.  If this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <tt>Integer.MAX_VALUE</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the number of elements in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    int size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Returns <tt>true</tt> if this collection contains no elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return <tt>true</tt> if this collection contains no elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    boolean isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns <tt>true</tt> if this collection contains the specified element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * More formally, returns <tt>true</tt> if and only if this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * contains at least one element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param o element whose presence in this collection is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return <tt>true</tt> if this collection contains the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *         element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @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
   166
     *         is incompatible with this collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   167
     *         (<a href="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @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
   169
     *         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
   170
     *         (<a href="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns an iterator over the elements in this collection.  There are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * guarantees concerning the order in which the elements are returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * (unless this collection is an instance of some class that provides a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * guarantee).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return an <tt>Iterator</tt> over the elements in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Returns an array containing all of the elements in this collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * If this collection makes any guarantees as to what order its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * are returned by its iterator, this method must return the elements in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * the same order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>The returned array will be "safe" in that no references to it are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * maintained by this collection.  (In other words, this method must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * allocate a new array even if this collection is backed by an array).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * The caller is thus free to modify the returned array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <p>This method acts as bridge between array-based and collection-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return an array containing all of the elements in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    Object[] toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Returns an array containing all of the elements in this collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * the runtime type of the returned array is that of the specified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * If the collection fits in the specified array, it is returned therein.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Otherwise, a new array is allocated with the runtime type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * specified array and the size of this collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p>If this collection fits in the specified array with room to spare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * (i.e., the array has more elements than this collection), the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * in the array immediately following the end of the collection is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <tt>null</tt>.  (This is useful in determining the length of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * collection <i>only</i> if the caller knows that this collection does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * not contain any <tt>null</tt> elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <p>If this collection makes any guarantees as to what order its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * are returned by its iterator, this method must return the elements in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * the same order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p>Like the {@link #toArray()} method, this method acts as bridge between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * array-based and collection-based APIs.  Further, this method allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * precise control over the runtime type of the output array, and may,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * under certain circumstances, be used to save allocation costs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>Suppose <tt>x</tt> is a collection known to contain only strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The following code can be used to dump the collection into a newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * allocated array of <tt>String</tt>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *     String[] y = x.toArray(new String[0]);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <tt>toArray()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
18829
ec84f0c313b0 8020409: Clean up doclint problems in java.util package, part 1
bpb
parents: 18824
diff changeset
   235
     * @param <T> the runtime type of the array to contain the collection
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param a the array into which the elements of this collection are to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *        stored, if it is big enough; otherwise, a new array of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *        runtime type is allocated for this purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return an array containing all of the elements in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws ArrayStoreException if the runtime type of the specified array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *         is not a supertype of the runtime type of every element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *         this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @throws NullPointerException if the specified array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    <T> T[] toArray(T[] a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Ensures that this collection contains the specified element (optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * operation).  Returns <tt>true</tt> if this collection changed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * result of the call.  (Returns <tt>false</tt> if this collection does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * not permit duplicates and already contains the specified element.)<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Collections that support this operation may place limitations on what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * elements may be added to this collection.  In particular, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * collections will refuse to add <tt>null</tt> elements, and others will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * impose restrictions on the type of elements that may be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Collection classes should clearly specify in their documentation any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * restrictions on what elements may be added.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * If a collection refuses to add a particular element for any reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * other than that it already contains the element, it <i>must</i> throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * an exception (rather than returning <tt>false</tt>).  This preserves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * the invariant that a collection always contains the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * after this call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param e element whose presence in this collection is to be ensured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return <tt>true</tt> if this collection changed as a result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *         call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *         is not supported by this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *         prevents it from being added to this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *         collection does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @throws IllegalArgumentException if some property of the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *         prevents it from being added to this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *         time due to insertion restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Removes a single instance of the specified element from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * collection, if it is present (optional operation).  More formally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * removes an element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * this collection contains one or more such elements.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <tt>true</tt> if this collection contained the specified element (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * equivalently, if this collection changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param o element to be removed from this collection, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @return <tt>true</tt> if an element was removed as a result of this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @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
   296
     *         is incompatible with this collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   297
     *         (<a href="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @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
   299
     *         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
   300
     *         (<a href="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *         is not supported by this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    // Bulk Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Returns <tt>true</tt> if this collection contains all of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * in the specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param  c collection to be checked for containment in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return <tt>true</tt> if this collection contains all of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *         in the specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *         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
   318
     *         collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   319
     *         (<a href="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *         or more null elements and this collection 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
   322
     *         elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   323
     *         (<a href="#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
   324
     *         or if the specified collection is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see    #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    boolean containsAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Adds all of the elements in the specified collection to this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * (optional operation).  The behavior of this operation is undefined if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the specified collection is modified while the operation is in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * (This implies that the behavior of this call is undefined if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * specified collection is this collection, and this collection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * nonempty.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @param c collection containing elements to be added to this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return <tt>true</tt> if this collection changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *         is not supported by this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @throws ClassCastException if the class of an element of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *         collection prevents it from being added to this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @throws NullPointerException if the specified collection contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *         null element and this collection does not permit null elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *         specified collection prevents it from being added to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *         collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @throws IllegalStateException if not all the elements can be added at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *         this time due to insertion restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see #add(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    boolean addAll(Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Removes all of this collection's elements that are also contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * specified collection (optional operation).  After this call returns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * this collection will contain no elements in common with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param c collection containing elements to be removed from this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @return <tt>true</tt> if this collection changed as a result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *         call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @throws UnsupportedOperationException if the <tt>removeAll</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *         is not supported by this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *         in this collection are incompatible with the specified
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   368
     *         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="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @throws NullPointerException if this collection contains one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *         null elements and the specified collection does not support
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   372
     *         null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   373
     *         (<a href="#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
   374
     *         or if the specified collection is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    boolean removeAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
17166
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   381
     * Removes all of the elements of this collection that satisfy the given
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   382
     * predicate.  Errors or runtime exceptions thrown by the predicate are
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   383
     * relayed to the caller.
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   384
     *
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   385
     * @implSpec
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   386
     * The default implementation traverses all elements of the collection using
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   387
     * its {@link #iterator}.  Each matching element is removed using
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   388
     * {@link Iterator#remove()}.  If the collection's iterator does not
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   389
     * support removal then an {@code UnsupportedOperationException} will be
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   390
     * thrown on the first matching element.
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   391
     *
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   392
     * @param filter a predicate which returns {@code true} for elements to be
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   393
     *        removed
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   394
     * @return {@code true} if any elements were removed
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   395
     * @throws NullPointerException if the specified filter is null
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   396
     * @throws UnsupportedOperationException if the {@code remove}
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   397
     *         method is not supported by this collection's
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   398
     *         {@link #iterator}
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   399
     * @since 1.8
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   400
     */
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   401
    default boolean removeIf(Predicate<? super E> filter) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   402
        Objects.requireNonNull(filter);
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   403
        boolean removed = false;
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   404
        final Iterator<E> each = iterator();
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   405
        while (each.hasNext()) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   406
            if (filter.test(each.next())) {
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   407
                each.remove();
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   408
                removed = true;
c83a0fa44906 8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents: 16929
diff changeset
   409
            }
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
        return removed;
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
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Retains only the elements in this collection that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * specified collection (optional operation).  In other words, removes from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * this collection all of its elements that are not contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @param c collection containing elements to be retained in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @return <tt>true</tt> if this collection changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *         is not supported by this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *         in this collection are incompatible with the specified
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   426
     *         collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   427
     *         (<a href="#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @throws NullPointerException if this collection contains one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *         null elements and the specified collection 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
   430
     *         elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 7668
diff changeset
   431
     *         (<a href="#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
   432
     *         or if the specified collection is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    boolean retainAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Removes all of the elements from this collection (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * The collection will be empty after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *         is not supported by this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    void clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // Comparison and hashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Compares the specified object with this collection for equality. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * While the <tt>Collection</tt> interface adds no stipulations to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * general contract for the <tt>Object.equals</tt>, programmers who
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * implement the <tt>Collection</tt> interface "directly" (in other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * create a class that is a <tt>Collection</tt> but is not a <tt>Set</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * or a <tt>List</tt>) must exercise care if they choose to override the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <tt>Object.equals</tt>.  It is not necessary to do so, and the simplest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * course of action is to rely on <tt>Object</tt>'s implementation, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * the implementor may wish to implement a "value comparison" in place of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * the default "reference comparison."  (The <tt>List</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * <tt>Set</tt> interfaces mandate such value comparisons.)<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * The general contract for the <tt>Object.equals</tt> method states that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * equals must be symmetric (in other words, <tt>a.equals(b)</tt> if and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * only if <tt>b.equals(a)</tt>).  The contracts for <tt>List.equals</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * and <tt>Set.equals</tt> state that lists are only equal to other lists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * and sets to other sets.  Thus, a custom <tt>equals</tt> method for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * collection class that implements neither the <tt>List</tt> nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * <tt>Set</tt> interface must return <tt>false</tt> when this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * is compared to any list or set.  (By the same logic, it is not possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * to write a class that correctly implements both the <tt>Set</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * <tt>List</tt> interfaces.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @param o object to be compared for equality with this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @return <tt>true</tt> if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see Set#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @see List#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Returns the hash code value for this collection.  While the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <tt>Collection</tt> interface adds no stipulations to the general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * contract for the <tt>Object.hashCode</tt> method, programmers should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * take note that any class that overrides the <tt>Object.equals</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * method must also override the <tt>Object.hashCode</tt> method in order
1818
7847313afae6 6792545: Typo in java.util.Collection JavaDoc
darcy
parents: 2
diff changeset
   491
     * to satisfy the general contract for the <tt>Object.hashCode</tt> method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * In particular, <tt>c1.equals(c2)</tt> implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <tt>c1.hashCode()==c2.hashCode()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @return the hash code value for this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @see Object#hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    int hashCode();
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   501
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   502
    /**
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   503
     * Creates a {@link Spliterator} over the elements in this collection.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   504
     *
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   505
     * <p>The returned {@code Spliterator} must report the characteristic
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   506
     * {@link Spliterator#SIZED}; implementations should document any additional
19424
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   507
     * characteristic values reported by the returned spliterator.  If
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   508
     * this collection contains no elements then the returned spliterator is
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   509
     * only required to report {@link Spliterator#SIZED} and is not required to
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   510
     * report additional characteristic values (if any).
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   511
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   512
     * <p>The default implementation should be overridden by subclasses that
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   513
     * can return a more efficient spliterator.  In order to
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   514
     * preserve expected laziness behavior for the {@link #stream()} and
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   515
     * {@link #parallelStream()}} methods, spliterators should either have the
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   516
     * characteristic of {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   517
     * <em><a href="Spliterator.html#binding">late-binding</a></em>.
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   518
     * If none of these is practical, the overriding class should describe the
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   519
     * spliterator's documented policy of binding and structural interference,
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   520
     * and should override the {@link #stream()} and {@link #parallelStream()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   521
     * methods to create streams using a {@code Supplier} of the spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   522
     * as in:
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   523
     * <pre>{@code
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   524
     *     Stream<E> s = StreamSupport.stream(() -> spliterator(), spliteratorCharacteristics)
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   525
     * }</pre>
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   526
     * <p>These requirements ensure that streams produced by the
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   527
     * {@link #stream()} and {@link #parallelStream()} methods will reflect the
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   528
     * contents of the collection as of initiation of the terminal stream
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   529
     * operation.
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   530
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   531
     * @implSpec
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   532
     * The default implementation creates a
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   533
     * <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   534
     * from the collections's {@code Iterator}.  The spliterator inherits the
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   535
     * <em>fail-fast</em> properties of the collection's iterator.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   536
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   537
     * @implNote
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   538
     * The returned {@code Spliterator} additionally reports
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   539
     * {@link Spliterator#SUBSIZED}.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   540
     *
19424
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   541
     * <p>If a spliterator covers no elements then the reporting of additional
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   542
     * characteristic values, beyond that of {@code SIZED} and {@code SUBSIZED},
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   543
     * does not aid clients to control, specialize or simplify computation.
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   544
     * However, this does enable shared use of an immutable and empty
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   545
     * spliterator instance (see {@link Spliterators#emptySpliterator()}) for
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   546
     * empty collections, and enables clients to determine if such a spliterator
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   547
     * covers no elements.
c4524285927f 8022797: Clarify spliterator characteristics for collections containing no elements
psandoz
parents: 18829
diff changeset
   548
     *
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   549
     * @return a {@code Spliterator} over the elements in this collection
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   550
     * @since 1.8
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   551
     */
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   552
    default Spliterator<E> spliterator() {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   553
        return Spliterators.spliterator(this, 0);
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   554
    }
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   555
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   556
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   557
     * Returns a sequential {@code Stream} with this collection as its source.
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   558
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   559
     * <p>This method should be overridden when the {@link #spliterator()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   560
     * method cannot return a spliterator that is {@code IMMUTABLE},
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   561
     * {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   562
     * for details.)
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   563
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   564
     * @implSpec
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   565
     * The default implementation creates a sequential {@code Stream} from the
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   566
     * collection's {@code Spliterator}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   567
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   568
     * @return a sequential {@code Stream} over the elements in this collection
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   569
     * @since 1.8
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   570
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   571
    default Stream<E> stream() {
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17182
diff changeset
   572
        return StreamSupport.stream(spliterator(), false);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   573
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   574
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   575
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   576
     * Returns a possibly parallel {@code Stream} with this collection as its
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   577
     * source.  It is allowable for this method to return a sequential stream.
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   578
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   579
     * <p>This method should be overridden when the {@link #spliterator()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   580
     * method cannot return a spliterator that is {@code IMMUTABLE},
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   581
     * {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   582
     * for details.)
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   583
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   584
     * @implSpec
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   585
     * The default implementation creates a parallel {@code Stream} from the
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   586
     * collection's {@code Spliterator}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   587
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   588
     * @return a possibly parallel {@code Stream} over the elements in this
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   589
     * collection
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   590
     * @since 1.8
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   591
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   592
    default Stream<E> parallelStream() {
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17182
diff changeset
   593
        return StreamSupport.stream(spliterator(), true);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents: 17166
diff changeset
   594
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
}