Here you can find the source of splitWords(String name)
public static List<String> splitWords(String name)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static List<String> splitWords(String name) { name = name.replaceAll("_{2,}", "_"); name = name.replaceAll("-{2,}", "-"); List<String> result = new ArrayList<>(); StringBuilder currentWord = new StringBuilder(name.length()); for (int i = 0, len = name.length(); i < len; i++) { char c = name.charAt(i); char next = i == len - 1 ? '\0' : name.charAt(i + 1); char prev = i == 0 ? '\0' : name.charAt(i - 1); if ((c == '_' || c == '-') && !(Character.isDigit(next) && Character.isDigit(prev))) { if (currentWord.length() > 0) { result.add(currentWord.toString()); currentWord.setLength(0); }/*from w w w.ja v a 2s. co m*/ continue; } if (Character.isUpperCase(c) && (!Character.isUpperCase(prev) || Character.isLowerCase(next))) { if (currentWord.length() > 0) { result.add(currentWord.toString()); currentWord.setLength(0); } } currentWord.append(c); } result.add(currentWord.toString()); return result; } }