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