Here you can find the source of split(final String str, final String delimiter)
Parameter | Description |
---|---|
str | A String |
delimiter | Token delimiter |
public static String[] split(final String str, final String delimiter)
//package com.java2s; /*L/*from w w w . ja v a 2s . co m*/ * Copyright RTI International * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/webgenome/LICENSE.txt for details. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Split string into separate tokens. * @param str A String * @param delimiter Token delimiter * @return Array of tokens */ public static String[] split(final String str, final String delimiter) { List<String> tokens = new ArrayList<String>(); int p = 0; while (p < str.length()) { int q = str.indexOf(delimiter, p); if (q < 0) { q = str.length(); } if (p == q) { tokens.add(""); } else { tokens.add(str.substring(p, q).trim()); } p = q + 1; } String[] tokenStr = new String[0]; tokenStr = (String[]) tokens.toArray(tokenStr); return tokenStr; } }