Reversing a string is a common programming problem given while learning how to code and invoke logical thinking. However, there are more than one ways to solve this problem. The below article explains different ways to reverse a string in Java. The reverse of a string means printing the character of a string from end to start.
CODE:
class Create_New_String_Reverse_String
{
public static void main(String args[]) {
String str1 = “CodeSpeedy”;
System.out.println(“Original string: “+str1);
int n = str1.length();
String Reverse_String =””;
char ch;
for(int i=0;i<n;i++) {
ch = str1.charAt(i);
Reverse_String = ch + Reverse_String;
}
System.out.println(“Reversed string: “+Reverse_String);
}
}
OUTPUT:
Original string: CodeSpeedy
Reversed string: ydeepSedoC