Created
May 13, 2016 02:08
-
-
Save sylvia43/9b5b78d6cd03bb19c2e5a366c1abb99e to your computer and use it in GitHub Desktop.
Java vs. Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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