DEV Community

Cover image for Reverse A String - 5 Methods

Reverse A String - 5 Methods

Amritanshu Dev Rawat on June 08, 2021

Method 1 - String Builder / String Buffer // Using String builder and String buffer public class Method1 { public static void main(String...
Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Talk about over complicating things (for JavaScript at least)

function reverseStr(s) {
    return s.split("").reverse().join("");
}
Enter fullscreen mode Exit fullscreen mode

Job done!

Also you could have at least used JavaScript if you were going to use the JavaScript tag, may I suggest you remove the JS tag from the post as beginners may be really confused and even experienced developers would probably have a few head scratches over trying to convert things like Stack<Character> charStack = new Stack<Character>(); to JS (I mean I can't even work out what the equivalent would be as I don't know that utility in Java)!

Collapse
 
amritanshu profile image
Amritanshu Dev Rawat

I am removing that :)

Collapse
 
pontakornth profile image
Pontakorn Paesaeng

Wait, it is not JavaScript. I think you put wrong tag.

Collapse
 
amritanshu profile image
Amritanshu Dev Rawat

But it may help JS developers also, as only syntax change :)

Collapse
 
javacode7 profile image
JavaCode7

You could implement this in almost every language.