0
How to reverse each word of a given string in java?
2 Answers
+ 4
String str = "Hello";
char[] reverse = new char[str.length()];
for(int i=str.length()-1, j=0; i>=0; i--, j++) reverse[j] = str.charAt(i);
System.out.println(new String(reverse));
+ 1
Or you can just do:
String str="Hello", reverse="";
for(int i=str.length()-1; i>=0; i--) reverse+=str.charAt(i);