Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gauravkukade/fb03909eb1a6644e00cc65c606cebf84 to your computer and use it in GitHub Desktop.
Save gauravkukade/fb03909eb1a6644e00cc65c606cebf84 to your computer and use it in GitHub Desktop.
A Java program to reverse a string. We are using 'reverse()' method of the StringBuilder class. This method rverse the character sequence represented by the string. The program is embedded at https://coderolls.com/reverse-a-string-in-java
/**
* A Java program to reverse a string.
*
* We are using 'reverse()' method of the StringBuilder class. This method rverse the
* character sequence represented by the string.
*
* @author Gaurav Kukade at coderolls.com
*/
public class ReverseStringUsingReverseMethodOfStringBuilder {
public static void main(String[] args) {
String blogName = "coderolls.com";
StringBuilder stringBuilder = new StringBuilder(blogName);
stringBuilder = stringBuilder.reverse();
System.out.print("The reversed string of the '"+blogName+"' is: ");
System.out.println(stringBuilder);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment