0 votes
1 view
in Java by (3.9k points)
I have "Hello World" kept in a String variable named hi.

I need to print it but reversed.

How can I do this? I understand there is some kind of a function already built-in into Java that does that.

1 Answer

0 votes
by (42.1k points)

You can try:

new StringBuilder(hi).reverse().toString()

Or, toward versions earlier than JDK 1.5, try java.util.StringBuffer rather than StringBuilder — both possess the same API. StringBuilder is favored nowadays as there's no concurrency matter.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !