Reversing a String: Java vs JavaScript vs Python


Reversing a String can be done in multiple ways, using functions, loops. Let us compare how it is done in Java, JavaScript and Python.

Input: Hello, How are You?

Output: ?uoY era woH ,olleH


public class ReverseString {
public static void main(String[] args)
System.out.println(new StringBuilder("Hello, How are You?").reverse().toString()); }


function reverseString(str) {
return str.split("").reverse().join("");
reverseString("Hello, How are You?");


> 'Hello, How are You?'[::-1]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s