src/share/classes/java/util/List.java
Print this page
rev 6197 : imported patch collections
*** 23,32 ****
--- 23,34 ----
* questions.
*/
package java.util;
+ import java.util.function.UnaryOperator;
+
/**
* An ordered collection (also known as a <i>sequence</i>). The user of this
* interface has precise control over where in the list each element is
* inserted. The user can access elements by their integer index (position in
* the list), and search for elements in the list.<p>
*** 595,600 ****
--- 597,631 ----
* @throws IndexOutOfBoundsException for an illegal endpoint index value
* (<tt>fromIndex < 0 || toIndex > size ||
* fromIndex > toIndex</tt>)
*/
List<E> subList(int fromIndex, int toIndex);
+
+ /**
+ * Apply the specified operator to each element of this list, replacing
+ * the element with the result of applying the operator to the current
+ * element.
+ *
+ * @param operator the operator to apply to each element
+ * @throws NullPointerException if the specified operator is null
+ * @since 1.8
+ */
+ public default void replaceAll(UnaryOperator<E> operator) {
+ Objects.requireNonNull(operator);
+ final ListIterator<E> li = this.listIterator();
+ while (li.hasNext()) {
+ li.set(operator.operate(li.next()));
+ }
+ }
+
+ /**
+ * Sort this list using the supplied {@code Comparator} to compare elements.
+ *
+ * @param c the {@code Comparator} used to compare list elements
+ * @throws NullPointerException if the specified comparator is null
+ * @since 1.8
+ */
+ public default void sort(Comparator<? super E> c) {
+ Objects.requireNonNull(c);
+ Collections.<E>sort(this, c);
+ }
}