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 in Java by Rahul
• 8,980 points
32 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 by Soham
• 8,730 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
437 views
0 votes
0 answers

Reverse a string in Java

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

Apr 14 in Java by Rahul
• 2,540 points
16 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,170 points
1,006 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,120 points
2,452 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,120 points
198 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,900 points
2,643 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
216 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
180 views
0 votes
3 answers

Change date format in a Java string

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

answered Feb 9 in Java by Soham
• 8,730 points
1,091 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 in Java by Soham
• 8,730 points
353 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP