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 )

Facebook photo

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

Connecting to %s