Following example shows how to reverse the String using StringBuffer.
Sample Program
package com.javatutorialcorner.javastring;
public class StringReverse {
public static void main(String[] args) {
String inputString = "Madam";
String reversedString = new StringBuffer(inputString).reverse()
.toString();
System.out.println("Input String : " + inputString);
System.out.println("Reversed String : " + reversedString);
}
}
Output
The above code will produce the following output
Input String : Madam
Reversed String : madaM
0 comments:
Post a Comment