Java String Split split(final String string)

Here you can find the source of split(final String string)

Description

Dada una cadena escrita en camelCase retorna una lista con los elementos que forman la cadena

Por ejemplo

  1. HolaMundo, retorna [Hola,Mundo]

License

Open Source License

Parameter

Parameter Description
string cadena a partir

Return

list de elementos

Declaration

public static List<String> split(final String string) 

Method Source Code


//package com.java2s;
/*-//from   ww w.  j ava2s  .  c o  m
 * Copyright (c)
 *
 *       2012-2014, Facultad Polit?cnica, Universidad Nacional de Asunci?n.
 *       2012-2014, Facultad de Ciencias M?dicas, Universidad Nacional de Asunci?n.
 *       2012-2013, Centro Nacional de Computaci?n, Universidad Nacional de Asunci?n.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    private static final List<Character> MAYUSCULAS = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
            'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

    /**
    * Dada una cadena escrita en camelCase retorna una lista con los elementos
    * que forman la cadena
    * <p>
    * <b>Por ejemplo</b>
    * <ol>
    * <li><b>HolaMundo</b>, retorna [Hola,Mundo]</li>
    * </ol>
    * 
    * </p>
    * 
    * @param string
    *            cadena a partir
    * @return list de elementos
    */
    public static List<String> split(final String string) {

        List<String> list = new ArrayList<String>();
        int j = 0;
        for (int i = 1; i < string.length(); i++) {
            if (MAYUSCULAS.contains(string.charAt(i))) {
                list.add(string.substring(j, i));
                j = i;
            }
        }
        list.add(string.substring(j, string.length()));
        return list;
    }
}

Related

  1. split(final String s)
  2. split(final String s)
  3. split(final String s)
  4. split(final String str)
  5. split(final String str)
  6. split(final String string)
  7. split(final String string, final String toSplit)
  8. split(final String text, final String sp)
  9. split(final String toSplit)