Here you can find the source of splitCamelCase(final String s)
Parameter | Description |
---|---|
s | the camel case string |
public static String[] splitCamelCase(final String s)
//package com.java2s; /**/* w ww . j a v a 2 s.com*/ * Copyright (c) 2008-2009 Acuity Technologies, Inc. * * 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. * * Created Jan 1, 2008 */ import java.util.ArrayList; public class Main { /** * Splits a camel case string into individual words. * * @param s * the camel case string * @return the individual words as a string array */ public static String[] splitCamelCase(final String s) { final ArrayList<String> words = new ArrayList<String>(); final int length = s.length(); int i = 0; final StringBuilder sb = new StringBuilder(); while (i < length) { while (i < length && Character.isUpperCase(s.charAt(i))) { sb.append(s.charAt(i)); ++i; } while (i < length && !Character.isUpperCase(s.charAt(i))) { sb.append(s.charAt(i)); ++i; } final String word = sb.toString(); words.add(word); sb.setLength(0); } return words.toArray(new String[words.size()]); } }