I am a new bie to the world of java , I was going through array , in an interview it was being asked from me write a code to reverse an array , I have gone through the following approach.. using Apache commons ArrayUtils class , but please advise how can the same thing be achieved through java itself, below is the my approach
int[] iArray = new int[] {101,102,103,104,105};
String[] sArray = new String[] {"one", "two", "three", "four", "five"};
System.out.println("Original int array : " + Arrays.toString(iArray));
ArrayUtils.reverse(iArray); System.out.println("reversed int array : " + Arrays.toString(iArray));
System.out.println("Original String array : " + Arrays.toString(sArray)); ArrayUtils.reverse(sArray); System.out.println("reversed String array in Java : " + Arrays.toString(sArray));
Output :-
Original int array : [101, 102, 103, 104, 105] reversed int array : [105, 104, 103, 102, 101] Original String array : [one, two, three, four, five] reversed String array in Java : [five, four, three, two, one]
Please advise how we can achieve the same thing in java itself.