Sunday, March 13, 2016

Java Examples : How To Reverse A String Using StringBuffer Class

Intro


This articles, will demonstrates how to reverse a String using StringBuffer class. To reverse a string, you can use the reverse() method of the StringBuffer class.

Examples


package com.freesamplecode.java.basic;

public class StringBufferReverseDemo {
	public static void main(String[] args){
		StringBuffer sb = new StringBuffer("Learning Java Programming is very nice");
		
		System.out.println("Original String : "+sb);
		
		//reverse the original string
		sb.reverse();
		
		System.out.println("Reversed String : "+sb);
		
	}
}


Output


Original String : Learning Java Programming is very nice
Reversed String : ecin yrev si gnimmargorP avaJ gninraeL


Screenshot


How To Reverse A String Using StringBuffer Class

Related Posts:

0 comments: