Answers for "inverse string"

2

how to reverse a string

function reverseString(str) {
    return str.split("").reverse().join("");
}
reverseString("hello");
Posted by: Guest on May-13-2020
8

reverse string method python

#linear

def reverse(s): 
  str = "" 
  for i in s: 
    str = i + str
  return str

#splicing
'hello world'[::-1]

#reversed & join
def reverse(string): 
    string = "".join(reversed(string)) 
    return string
Posted by: Guest on January-12-2020
0

reverse a string

String -- Reverse
Write a return method that can reverse  String
Ex: Reverse("ABCD"); ==> DCBA

USING CORE JAVA
public static String StrReverse(String str) {
String reverse="";
for(int i=str.length()-1; i >= 0; i--)
reverse += str.toCharArray()[i];
 
return  reverse;
}
 
USING STRING BUFFER/BUILDER
public static String  Reverse(String str) {
return new StringBuffer(str).reverse().toString();
}
Posted by: Guest on September-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language