Java IntStream reverse int array

Description

Java IntStream reverse int array


import java.util.Arrays;
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    System.out.println(Arrays.toString(array));

    Object[] reverseArray = IntStream.rangeClosed(1, array.length)
        .mapToObj(i -> array[array.length - i])
        .toArray();// ww  w . j av a  2 s  . co m
    
    System.out.println(Arrays.toString(reverseArray));

  }
}



PreviousNext

Related