0

How do you take a reverse action on a string?

Lets say you have string value of "how",i want to print "woh"..in reverse order

4th Oct 2021, 2:58 PM
Rio
5 Respuestas
+ 2
Many ways but simply use loop start print values from index string.length-1th to 0th index value.
4th Oct 2021, 3:00 PM
Jayakrishna 🇮🇳
+ 3
You can also create a StringBuilder object that takes the string as an argument of its constructor then simply use .reverse () method
4th Oct 2021, 3:10 PM
Melek
Melek - avatar
+ 2
U can use predefined method or u can do it via loop start loop from total length of string to till 0
4th Oct 2021, 3:00 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Reverse a String using CharAt Method In the below given Java program will help you to understand how to reverse a String entered by the user. Here, I have used the CharAt() method in order to extract the characters from the input String. The main task of the CharAt() method is to return the character at the specified index in the given String. Then, I have appended them in reverse order to reverse the given String. It is one of the simple approaches to reverse a String in Java. If you want to take a (small) step further, here's a Java 8+ one-liner: Function<String, String> reverse = s -> new StringBuilder(s).reverse().toString();
4th Oct 2021, 4:51 PM
Arun Jamson
Arun Jamson - avatar