Arrays.parallelSort(…)

In Java 8 sind neue Sortiermethoden hinzugekommen, die für sehr große Felder geeignet sind. Bei den neuen parallelSort(…)-Methoden verwendet die Bibliothek mehrere Threads um Teile parallel zu sortieren, was die Geschwindigkeit erhöhen kann. Eine Garantie ist das aber nicht, denn ein Performance-Vorteil ergibt sich wirklich nur bei großen Feldern.

class java.util.Arrays

§ static void parallelSort(byte[] a)

§ static void parallelSort(byte[] a, int fromIndex, int toIndex)

§ static void parallelSort(char[] a)

§ static void parallelSort(char[] a, int fromIndex, int toIndex)

§ static void parallelSort(short[] a)

§ static void parallelSort(short[] a, int fromIndex, int toIndex)

§ static void parallelSort(int[] a)

§ static void parallelSort(int[] a, int fromIndex, int toIndex)

§ static void parallelSort(long[] a)

§ static void parallelSort(long[] a, int fromIndex, int toIndex)

§ static void parallelSort(float[] a)

§ static void parallelSort(float[] a, int fromIndex, int toIndex)

§ static void parallelSort(double[] a)

§ static void parallelSort(double[] a, int fromIndex, int toIndex)

§ static <T extends Comparable<? super T>> void parallelSort(T[] a)

§ static <T extends Comparable<? super T>> void parallelSort(T[] a, int fromIndex, int toIndex)

§ static <T> void parallelSort(T[] a, Comparator<? super T> c)

§ static <T> void parallelSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)

Der verwendete Algorithmus ist einfach zu verstehen: zunächst wird das Feld ist Teilfelder partitioniert, die werden dann parallel sortiert und dann zu einem größeren sortierten Feld zusammengelegt. Das Verfahren nennt sich auch parallel sort-merge.

Na endlich sieht Java 8’s Optional-Typ besser aus

http://download.java.net/jdk8/docs/api/java/util/Optional.html:

static <T> Optional<T>
empty()

Returns an empty Optional instance.

boolean
equals(Object obj)

Indicates whether some other object is "equal to" this Optional.

T
get()

If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.

int
hashCode()

Returns the hash code value of the present value, if any, or 0 (zero) if no value is present.

void
ifPresent(Consumer<? super T> consumer)

Have the specified consumer accept the value if a value is present, otherwise do nothing.

boolean
isPresent()

Return true if there is a value present, otherwise false.

static <T> Optional<T>
of(T value)

Return an Optional with the specified present value.

T
orElse(T other)

Return the value if present, otherwise return other.

T
orElseGet(Supplier<? extends T> other)

Return the value if present, otherwise invoke other and return the result of that invocation.

<X extends Throwable>
T

orElseThrow(Supplier<? extends X> exceptionSupplier)

Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.

String
toString()

Returns a non-empty string representation of this Optional suitable for debugging.

 

Was mir immer noch fehlt: fromNullable(v). Arg, das fehlt.