Here you can find the source of split(String str, char ch, int size)
Parameter | Description |
---|---|
str | the string |
ch | the delimiting char |
public static String[] split(String str, char ch, int size)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { /**/*from w ww. j a va 2s . com*/ * Splits the specified string around matches of the given * delimiting char. * * @param str the string * @param ch the delimiting char * @return the list of strings computed by splitting the string around * matches of the given char */ public static String[] split(String str, char ch, int size) { String[] a = new String[size]; //long b = System.nanoTime(); int j = str.indexOf(ch), k = 0, i = 0; //logger.info("j = " + j); while (j != -1) { a[i++] = str.substring(k, j); //logger.info(k + "\t" + j + "\t'" + str.substring(k, j) + "'"); str = str.substring(j + 1, str.length()); //logger.info(k + "\t" + j + "\t'" + str + "'"); j = str.indexOf(ch); ///logger.info("j = " + j); } a[i++] = str.substring(j + 1, str.length()); //logger.info(k + "\t" + j + "\t'" + str + "'"); return a; } /** * Splits the specified string around matches of the given * delimiting char. * * @param str the string * @param ch the delimiting char * @return the list of strings computed by splitting the string around * matches of the given char */ public static List<String> split(String str, char ch) { List<String> list = new ArrayList<String>(); //long b = System.nanoTime(); int j = str.indexOf(ch), k = 0; //logger.info("j = " + j); while (j != -1) { list.add(str.substring(k, j)); //logger.info(k + "\t" + j + "\t'" + str.substring(k, j) + "'"); str = str.substring(j + 1, str.length()); //logger.info(k + "\t" + j + "\t'" + str + "'"); j = str.indexOf(ch); ///logger.info("j = " + j); } str = str.substring(j + 1, str.length()); list.add(str); //logger.info(k + "\t" + j + "\t'" + str + "'"); return list; } }