-
-
Save digitalconceptvisuals/c479b77cf3f2759df9b325a67775aa99 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* CamelConverter makes | |
* first word all lower | |
* subsequent words firt letter upper, rest lower | |
* "TWO", "WORDS" -> "twoWords" | |
*/ | |
class CamelConverter implements CaseConverter { | |
@Override | |
public String convert(String... words) { | |
// Accumulate result in StringBuilder | |
StringBuilder result = new StringBuilder(); | |
// First word is all lower | |
result.append( | |
words[0] | |
.trim() | |
.toLowerCase() | |
); | |
// Subsequent words are | |
// first -> upper | |
// rest -> lower | |
for (int offset = 1; | |
offset < words.length; | |
offset++) { | |
// First letter is upper | |
result.append( | |
words[offset] | |
.substring(0, 1) | |
.toUpperCase() | |
); | |
// Remaining letters are lower | |
result.append( | |
words[offset] | |
.substring(1) | |
.toLowerCase()); | |
} | |
return result.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment