Below java code snippet will be responsible to reverse any string.
Output:
Before reversing the string: JAVA
After reversing the string: AVAJ
public class ReverseStringTest {
public static void main(String[] args) {
String inOrder = "JAVA";
String reverse = new StringBuffer(inOrder).reverse().toString();
System.out.println("Before reversing the string: " + inOrder);
System.out.println("After reversing the string: " + reverse);
}
}
Output:
Before reversing the string: JAVA
After reversing the string: AVAJ
No comments:
Post a Comment