Created
November 21, 2015 08:09
-
-
Save recursivecurry/6afebb8e2f33b72f616a to your computer and use it in GitHub Desktop.
CamelCase
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
import java.io.*; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; | |
public class CamelCase { | |
public static String camelCase(String word) { | |
final String[] wordList = word.split("-"); | |
return Stream.of(Arrays.copyOfRange(wordList, 1, wordList.length)).map(w -> | |
w.substring(0, 1).toUpperCase() + w.substring(1) | |
).reduce(wordList[0], (acc, val) -> acc + val); | |
} | |
public static void main(String[] args) { | |
System.out.println(camelCase("aa-bb-cc")); | |
System.out.println(camelCase("abc")); | |
System.out.println(camelCase("ABC")); | |
System.out.println(camelCase("A-bb-Ca")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
저도 참고해서 조금더 짧게 다듬어 봤습니다.