Java Arrays sort via Stream

Description

Java Arrays sort via Stream

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Integer[] values = {12, 19, 5, 10, 3, 17, 1, 4, 8, 6};

    // display original values
    System.out.printf("Original values: %s%n", Arrays.asList(values));

    // sort values in ascending order with streams
    List<Integer> list = Arrays.stream(values)
             .sorted()//from  w  w w.ja v  a  2 s .c o  m
             .collect(Collectors.toList());

    System.out.println(list);
 }
}



PreviousNext

Related