JavaNames { public static String[] tokenize(final String s) { final List<String> result = new ArrayList<>(); int start = 0; boolean uppercaseToken = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (! Character.isJavaIdentifierPart(c) || (result.isEmpty() && start == i && !Character.isJavaIdentifierStart(c))) { c = '_'; } if (Character.isLowerCase(c) || Character.isDigit(c)) { if (uppercaseToken) { add(result, start, i-1, s); start = i-1; uppercaseToken = false; } } else if (Character.isUpperCase(c)) { if (!uppercaseToken) { add(result, start, i, s); start = i; } if (start == i) { uppercaseToken = true; } else { assert uppercaseToken : "token should be uppercase"; } } else { add(result, start, i, s); start = i+1; uppercaseToken = false; } } add(result, start, s.length(), s); return result.toArray(new String[result.size()]); }  static String[] tokenize(final String s); static String firstToUpper(String s); static StringBuilder appendFirstToUpper(StringBuilder target, String s); static String[] allToLower(final String... tokens); static String[] allToUpper(final String... tokens); static String[] allToCamel(final String... tokens); static String camelCase(String string); static String CamelCase(String string); static StringBuilder camelCase(final StringBuilder target, boolean firstToLower, final String... tokens); static StringBuilder under_score(final StringBuilder sb, final String... tokens); static StringBuilder UNDER_SCORE(final StringBuilder sb, final String... tokens); static String under_score(String string); static String UNDER_SCORE(String string);  }
@Test public void test_tokenize() { assertThat(tokenize("hello"), isArray("hello")); assertThat(tokenize("helloWorld"), isArray("hello", "World")); assertThat(tokenize("hello_World"), isArray("hello", "World")); assertThat(tokenize("HTTPRequest"), isArray("HTTP", "Request")); assertThat(tokenize("HE_wo"), isArray("HE", "wo")); }