StringBuilder str = new StringBuilder("Hello World"); str.reverse(); System.out.println(str); // Output: dlroW olleH
String str = "abcd"; StringBuilder sb = new StringBuilder(str); sb.reverse(); System.out.println(sb); // Output: dcbaIn this example, we first create a string variable "str" with the value "abcd". Then we initialize a StringBuilder object sb with the value of str. Next, we use the reverse() method to reverse the string builder's contents. Finally, we print the reverse content of the string builder. Therefore, in Java, to reverse a string, we can utilize the reverse method of the StringBuilder class. This method reverses the content of a StringBuilder instance. The StringBuilder reverse method is found in the java.lang package library.