0

How to reverse an array without using another array

13th Dec 2017, 8:48 AM
Ashwini
3 Respostas
+ 8
Collections.reverse() can do that job for you if you put your numbers in a Listof Integers. List<Integer> list = Arrays.asList(1, 4, 9, 16, 9, 7, 4, 9, 11); System.out.println(list); Collections.reverse(list); System.out.println(list);
13th Dec 2017, 9:04 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
A variable. Save the first cell of the array in a temp. take last cell content to the first one. move temp to last cell. repeat with second cell and cell before last and so on... If array len is even, reach the middle. if array len is not even, the middle cell does not move.
13th Dec 2017, 9:02 AM
Amir Galanty
Amir Galanty - avatar
0
int[] array = {1,2,3}; ArrayUtils.reverse(array);
13th Dec 2017, 9:04 AM
Dima Makieiev
Dima Makieiev - avatar