Here you can find the source of split(String str, String delimiter, int limit)
public static String[] split(String str, String delimiter, int limit)
//package com.java2s; /*//w w w.ja va2 s.c om * Copyright (C) 2014 Vincent Quatrevieux <quatrevieux.vincent@gmail.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 3 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, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; public class Main { public static String[] split(String str, String delimiter, int limit) { ArrayList<String> splited = new ArrayList<String>(); int last = 0, pos, step = 0; if (limit < 1) { limit = Integer.MAX_VALUE; //devrait suffire amplement x) } while ((pos = str.indexOf(delimiter, last)) != -1 && ++step < limit) { splited.add(str.substring(last, pos)); last = pos + 1; } splited.add(str.substring(last)); String[] ret = new String[splited.size()]; return splited.toArray(ret); } public static String[] split(String str, String delimiter) { return split(str, delimiter, 0); } }