How To Reverse A String In Java?

Use `StringBuilder` and `reverse()`

`String reversed = new StringBuilder(str).reverse().toString();`

Use a `char[]` and swap characters from both ends

Use a `for` loop to build the reversed string

Use recursion

Use `StringBuffer` and `reverse()`

Use `Collections.reverse()` on a list of characters

Use Java Streams to reverse characters

Use a stack to pop characters in reverse order

Suggested for You

Trending Today