You are here : Home / Core Java Tutorials / Interview Programs (beginner to advanced) in java / Level1 programs (beginner)
In this programming tutorial we will learn how to reverse String in java with example, diagram and program by using StringBuffer in java.
Example in java -
String: abcde
output: edcba
Full Program/Example >
/** Copyright (c), AnkitMittal www.JavaMadeSoEasy.com */
public class ReverseStringUsingStringBufferExample {
public static void main(String...args){
String originalString="abcde"; //String to be reversed
StringBuffer sb=new StringBuffer(originalString);
System.out.println("Original String: "+originalString);
System.out.println("Reversed String: "+sb.reverse());
}
}
/*OUTPUT
Original String: abcde
Reversed String: edcba
*/
|
So in this programming tutorial we learned how to reverse String in java with example, diagram and program by using StringBuffer in java.
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>
Labels:
Core Java
Level1 programs (beginners)