Skip to content

Instantly share code, notes, and snippets.

@lobster1234
Last active February 21, 2018 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lobster1234/5036770 to your computer and use it in GitHub Desktop.
Save lobster1234/5036770 to your computer and use it in GitHub Desktop.
Reverse a String - Scala
def reverseString(s:String) = (for(i<-s.length-1 to 0 by -1) yield s(i)).mkString
//Java Version here:
public class Test {
public final String reverse(String s) {
StringBuffer b = new StringBuffer(s.length());
for(int i = s.length()-1; i >=0; i--){
b.append(s.charAt(i));
}
return b.toString();
}
public static void main(String[] args) {
System.out.println(new Test().reverse("A"));
System.out.println(new Test().reverse("Manish"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment