Java String Split by Case splitCamelCase(String src)

Here you can find the source of splitCamelCase(String src)

Description

split Camel Case

License

Open Source License

Declaration

public static List<String> splitCamelCase(String src) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> splitCamelCase(String src) {
        List<String> tokens = new ArrayList<>();
        int wordStart = 0;
        char c = src.charAt(0);
        int capsCount = Character.isUpperCase(c) ? 1 : 0;
        for (int i = 1; i < src.length(); ++i) {
            c = src.charAt(i);/* ww  w .  jav  a  2 s .c om*/
            if (Character.isUpperCase(c)) {
                switch (capsCount) {
                case 0:
                    tokens.add(src.substring(wordStart, i));
                    wordStart = i;
                    break;
                default:
                    break;
                }
                capsCount += 1;
            } else {
                switch (capsCount) {
                case 0:
                case 1:
                    break;
                default:
                    tokens.add(src.substring(wordStart, i - 1));
                    wordStart = i - 1;
                }
                capsCount = 0;
            }
        }
        tokens.add(src.substring(wordStart, src.length()));
        return tokens;
    }
}

Related

  1. split(String pString, String pSeparator, boolean pIgnoreCase)
  2. splitByCamelCase(String name)
  3. splitByCharacterTypeCamelCase(String targetName)
  4. splitCamelCase(final String in)
  5. splitCamelCase(final String s)
  6. splitCamelCase(String string)
  7. splitOnUppercase(String input)
  8. splitString(String string, Character character, boolean encased)
  9. splitWords(String text, boolean toLowerCase)