Java String Split by Separator split(String s, char separator)

Here you can find the source of split(String s, char separator)

Description

Devuelve una cadena troceada.

License

Open Source License

Parameter

Parameter Description
s Cadena
separator Separador

Return

Array con los trozos de la cadena

Declaration

public static String[] split(String s, char separator) 

Method Source Code


//package com.java2s;
/*//from  ww w .  jav a 2s .  c  o m
 * Apime v1.0 - Framework for j2me applications.
 *
 * Copyright (c) 2004 Carlos Araiz (caraiz@java4ever.com)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program 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 General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.util.*;

public class Main {
    /**
     * Devuelve una cadena troceada.
     *
     * @param s Cadena
     * @param separator Separador
     *
     * @return Array con los trozos de la cadena
     */
    public static String[] split(String s, char separator) {
        Vector v = new Vector();
        for (int ini = 0, end = 0; ini < s.length(); ini = end + 1) {
            end = s.indexOf(separator, ini);
            if (end == -1)
                end = s.length();
            //
            String st = s.substring(ini, end);
            if (st.length() > 0)
                v.addElement(st);
        }
        //
        String temp[] = new String[v.size()];
        v.copyInto(temp);
        return temp;
    }
}

Related

  1. split(String s, char separator)
  2. split(String s, char separator)
  3. split(String s, char separator)
  4. split(String s, char separator)
  5. split(String s, char separator)
  6. split(String s, String separator)
  7. split(String s, String separator)
  8. split(String s, String separator)
  9. split(String s, String separator)