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 (46.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.

Related questions

0 votes
1 answer
asked Nov 26, 2019 in Java by Nigam (4.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 20, 2019 in Java by Nigam (4.1k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...