DEV Community

Discussion on: Reverse An Array - 3 Methods

Collapse
 
longwater1234 profile image
Davis Tibbz • Edited

Here is a crazy one 😀:

public static int[] reverse(int[] array) {
       return IntStream.range(0, array.length).map(i -> array[array.length - 1 - i]).toArray();
    }
 public static void main(String[] args) {
    //integer array 'a'
     var a = reverse(new int[]{2, 4, 5, 6, 7, 8});
    System.out.println(Arrays.toString(a));
    }
Enter fullscreen mode Exit fullscreen mode