CodesJava

Easy learning with example program codes

reverse() StringBuilder method in java

reverse(): replace the string builder’s character sequence by reverse character sequence.

Syntax:

public StringBuilder reverse()

Example:

StringBuilderReverseExample.java

/**
 * This program is used to show the use of reverse() method.
 * @author codesjava
 */
class TestStringBuilder{
	StringBuilder sb = 
                new StringBuilder("www.codesjava.com");
 
	/**
	 * This method is used to show the use of reverse() method.
	 * @author codesjava
	 */
	public void reverseTest(){
		//replace the string buffer’s character 
                //sequence by reverse character sequence.
		System.out.println(sb.reverse());
	}
}
 
public class StringBuilderReverseExample {
	public static void main(String args[]){
		//creating TestStringBuilder object
		TestStringBuilder obj = new TestStringBuilder();
 
		//method call
		obj.reverseTest();
	}
}

Output:

moc.avajsedoc.www

Download this example.
 
Next Topic: capacity() StringBuilder method in java.
Previous Topic: delete(int startIndex, int endIndex) StringBuilder method in java.

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status