Reverse a string in Java

0 votes
I have a "Hello World" kept in a String variable named hi. In order to print it in a reverse format, how could I do so? My understanding is that there is a function which is already inbuilt into Java that does the same. Could I please get help regarding this doubt?
Feb 8, 2022 in Java by Rahul
• 9,680 points
550 views

1 answer to this question.

0 votes

To answer your question, you can use the following line of code:-

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

The StringBuilder was added in Java 5. For the prior versions to Java 5, the StringBuffer class can be used instead which uses the same API.

answered Feb 8, 2022 by Soham
• 9,710 points

Related Questions In Java

0 votes
3 answers

How to reverse a string in java?

public static String reverse(String s) { ...READ MORE

answered Aug 17, 2018 in Java by samarth295
• 2,220 points
1,570 views
0 votes
0 answers

Reverse a string in Java

I have "Hello World" kept in a ...READ MORE

Apr 14, 2022 in Java by Rahul
• 3,380 points
357 views
0 votes
1 answer

How to reverse a string in java word by word?

Here is the code to reverse a ...READ MORE

answered Dec 13, 2023 in Java by Anu
434 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
2,311 views
0 votes
1 answer

How can two strings be concatenated in java?

You can concatenate Strings using the + operator: System.out.println("Your number ...READ MORE

answered Jun 6, 2018 in Java by Daisy
• 8,140 points
823 views
0 votes
2 answers

How an object array can be converted to string array in java?

System.arraycopy is the most efficient way, but ...READ MORE

answered Aug 8, 2018 in Java by Sushmita
• 6,920 points
5,656 views
0 votes
1 answer

Why is char[] preferred over a string?

Strings are immutable. That means once you've ...READ MORE

answered Jun 14, 2018 in Java by scarlett
• 1,290 points
666 views
0 votes
1 answer

Can quotes be added in a java string.how?

In Java, you can escape quotes with \: String ...READ MORE

answered Jun 14, 2018 in Java by Akrati
• 960 points
693 views
0 votes
3 answers

Change date format in a Java string

The reason for the inaccuracy is because ...READ MORE

answered Feb 9, 2022 in Java by Soham
• 9,710 points
3,361 views
0 votes
2 answers

How do I convert a String to an int in Java?

Use the lines of code mentioned below:- String ...READ MORE

answered Feb 9, 2022 in Java by Soham
• 9,710 points
3,209 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP