StringBuilder reverse() in Java with Examples Last Updated : 11 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The reverse() method of StringBuilder is used to reverse the characters in the StringBuilder. The method helps to this character sequence to be replaced by the reverse of the sequence. Syntax: public java.lang.AbstractStringBuilder reverse() Returns: This method returns StringBuilder object after reversing the characters. Below programs illustrate the java.lang.StringBuilder.reverse() method: Example 1: Java // Java program to demonstrate // the reverse() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("WelcomeGeeks"); // print string System.out.println("String = " + str.toString()); // reverse the string StringBuilder reverseStr = str.reverse(); // print string System.out.println("Reverse String = " + reverseStr.toString()); } } Output: String = WelcomeGeeks Reverse String = skeeGemocleW Example 2: Java // Java program to demonstrate // the reverse() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("AAAABBBCCCC"); // print string System.out.println("String = " + str.toString()); // reverse the string StringBuilder reverseStr = str.reverse(); // print string System.out.println("Reverse String = " + reverseStr.toString()); } } Output: String = AAAABBBCCCC Reverse String = CCCCBBBAAAA References: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuilder.html#reverse() Comment More infoAdvertise with us Next Article StringBuilder charAt() in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Reverse Java-Functions Java-StringBuilder Practice Tags : JavaReverse Similar Reads StringBuilder replace() in Java with Examples The replace(int start, int end, String str) method of StringBuilder class is used to replace the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified index start and extends to the character at index end - 1 or to the end of the se 3 min read StringBuffer reverse() Method in Java with Examples The Java.lang.StringBuffer.reverse() is an inbuilt method that is used to reverse the characters in the StringBuffer. The method causes this character sequence to be replaced by the reverse of the sequence. Syntax: public StringBuffer reverse() Parameters: NA Return Value: The method returns the Str 2 min read StringBuilder delete() in Java with Examples The delete(int start, int end) method of StringBuilder class removes the characters starting from index start to index end-1 from String contained by StringBuilder. This method takes two indexes as a parameter first start represents index of the first character and endIndex represents index after th 3 min read StringBuilder charAt() in Java with Examples The charAt(int index) method of StringBuilder Class is used to return the character at the specified index of String contained by StringBuilder Object. The index value should lie between 0 and length()-1. Syntax: public char charAt(int index) Parameters: This method accepts one int type parameter in 3 min read StringBuilder toString() method in Java with Examples The toString() method of the StringBuilder class is the inbuilt method used to return a string representing the data contained by StringBuilder Object. A new String object is created and initialized to get the character sequence from this StringBuilder object and then String is returned by toString( 3 min read StringBuilder subSequence() in Java with Examples The subSequence(int start, int end) method of StringBuilder class is the inbuilt method used to return a subsequence of characters lie between index start and end-1 of this sequence. The subsequence starts with the char value at the index start and ends with the char value at (end-1). The length of 2 min read Like