Here you can find the source of splitCamelCase(final String in)
public static List<String> splitCamelCase(final String in)
//package com.java2s; /**/*ww w . ja v a 2s .c o m*/ * Copyright 2008 Matthew Hillsdon * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Splits camel case. * * Behaviour undefined for strings containing punctuation/whitespace. * Note that here uppercase is defined as !Character.isLowerCase(char) * notably, this includeds digits. */ public static List<String> splitCamelCase(final String in) { List<String> result = new ArrayList<String>(); char[] chars = in.toCharArray(); int takenLength = 0; boolean lastLower = false; boolean nextLower = isNextLower(chars, -1); boolean lastNeutral = false; boolean currentNeutral = false; for (int i = 0; i < chars.length; ++i) { boolean currentUpper = !nextLower; boolean lastUpper = !lastLower && i > 0; nextLower = isNextLower(chars, i); currentNeutral = isCurrentNeutral(chars, i); // Step up is e.g. aB, step down is Ab. boolean stepUp = lastLower && (currentUpper && !currentNeutral); boolean nextStepDown = (lastUpper && !lastNeutral) && (currentUpper && !currentNeutral) && nextLower; if (stepUp || nextStepDown) { result.add(in.substring(takenLength, i)); takenLength = i; } lastLower = !currentUpper; lastNeutral = currentNeutral; } result.add(in.substring(takenLength)); return result; } private static boolean isNextLower(final char[] chars, final int currentPos) { if (currentPos + 1 < chars.length) { char c = chars[currentPos + 1]; return Character.isLowerCase(c); } return false; } private static boolean isCurrentNeutral(final char[] chars, final int currentPos) { if (currentPos < chars.length) { char c = chars[currentPos]; return !Character.isLetterOrDigit(c); } return false; } }