Here you can find the source of explode(String src, String sep)
public static String[] explode(String src, String sep)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { public static String[] explode(String src, String sep) { if (src == null) { return null; }/* ww w .j a v a2 s .c om*/ ArrayList<String> outputTmp = new ArrayList<String>(); char[] buffer = src.toCharArray(); char[] delimiter = sep.toCharArray(); boolean separate = false; int start = 0; for (int i = 0; i < buffer.length; i++) { if (buffer[i] == delimiter[0]) { separate = true; if (i + delimiter.length <= buffer.length) { for (int j = 1; j < delimiter.length; j++) { if (buffer[i + j] != delimiter[j]) { separate = false; break; } } if (separate) { outputTmp.add(new String(buffer, start, i - start)); i += delimiter.length - 1; start = i + 1; } } } } outputTmp.add(new String(buffer, start, buffer.length - start)); return outputTmp.toArray(new String[0]); } }