java program to reverse a string without using string inbuilt function code example
Example 1: reverse string java
String string="whatever";
String reverse = new StringBuilder(string).reverse().toString();
System.out.println(reverse);
Example 2: java string reverse
String rev = new StringBuilder("Your String").reverse().toString();
Example 3: Reverse a string in java
class ReverseUsingReverseMethod
{
public static void main(String[] args)
{
String str = "Hello world Java";
StringBuilder sb = new StringBuilder();
sb.append(str);
sb = sb.reverse();
System.out.println(sb);
}
}
Example 4: reverse a string in java
public static String reverse(String str) {
char[] oldCharArray = str.toCharArray();
char[] newCharArray= new char[oldCharArray.length];
int currentChar = oldCharArray.length-1;
for (char c : oldCharArray) {
newCharArray[currentChar] = c;
currentChar--;
}
return new String(newCharArray);
}