StringBuilder reverse() in Java with Examples Last Updated : 11 Dec, 2022 Comments Improve Suggest changes 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 reverse() 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 StringBuilder lastIndexOf() method in Java with Examples In StringBuilder class, there are two types of lastIndexOf() method depending upon the parameters passed to it. lastIndexOf(String str) The lastIndexOf(String str) method of StringBuilder class is the inbuilt method used to return the index within the String for last occurrence of passed substring a 4 min read Short reverseBytes() in Java with Examples The reverseBytes() method of Short class is a built in method in Java which is used to return the value obtained by reversing the order of the bytes in the two's complement representation of the specified short value. Syntax : public static short reverseBytes(short a) Parameter: The method takes one 2 min read StringBuilder deleteCharAt() in Java with Examples The deleteCharAt(int index) method of StringBuilder class remove the character at the given index from String contained by StringBuilder. This method takes index as a parameter which represents the index of char we want to remove and returns the remaining String as StringBuilder Object. This StringB 3 min read StringBuilder offsetByCodePoints() method in Java with Examples The offsetByCodePoints() method of StringBuilder class returns the index within this String contained by StringBuilder that is offset from the index passed as parameter by codePointOffset code points. Unpaired surrogates lies between index and codePointOffset count as one code point each. Syntax: pu 2 min read Like