Java String Split by Case splitCamelCase(String string)

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

Description

split Camel Case

License

Apache License

Declaration

public static String[] splitCamelCase(String string) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] splitCamelCase(String string) {
        List<String> nodes = new ArrayList<String>();

        char[] chars = string.toCharArray();

        StringBuilder buff = new StringBuilder();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if (Character.isUpperCase(c)) {
                nodes.add(buff.toString());
                buff.delete(0, buff.length());
                buff.append(Character.toLowerCase(c));
            } else {
                buff.append(c);/*from ww  w .  j a  va  2  s.  c o  m*/
            }
        }

        if (buff.length() != 0) {
            nodes.add(buff.toString());
        }

        return nodes.toArray(new String[nodes.size()]);
    }
}

Related

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