Skip to content

Instantly share code, notes, and snippets.

@sylvia43
Created May 13, 2016 02:08
Show Gist options
  • Save sylvia43/9b5b78d6cd03bb19c2e5a366c1abb99e to your computer and use it in GitHub Desktop.
Save sylvia43/9b5b78d6cd03bb19c2e5a366c1abb99e to your computer and use it in GitHub Desktop.
Java vs. Scala
public String capitalize(String str) {
String[] words = str.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
words[i] = Character.toUpperCase(words[i].charAt(0)) + words[i].substring(1);
}
return TextUtils.join(" ", words);
}
def capitalize(str: String): String = str.toLowerCase().split(" ").map(_.capitalize).mkString(" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment