I have this input String input = "TOM DICK HARRY";
, I want output as "HARRY DICK TOM"
I have tried this (which I think is not an optimal way of doing)
public static void main(String[] args) {
String input = "TOM DICK HARRY";
String inputArr [] = input.split(" ");
for (int i = inputArr.length; i >0; i--) {
System.out.print(inputArr[i-1]+" ");
}
}
Is there any built in method to do this?