Here you can find the source of splitTrim(String str, String limitChar)
public static String[] splitTrim(String str, String limitChar)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static String[] splitTrim(String str, String limitChar) { if (str == null) { return null; }// www .j a va2 s .c om if ("".equals(str) || limitChar == null || "".equals(limitChar)) { return new String[] { str }; } int limitLength = limitChar.length(); if (limitLength > str.length()) { return new String[] { str }; } List<String> list = new ArrayList<String>(); int start = 0; for (int i = 0; i < str.length(); i++) { if (i + limitLength > str.length()) { break; } String cur = str.substring(i, i + limitLength); if (limitChar.equals(cur)) { list.add(str.substring(start, i)); start = i + limitLength; i += limitLength - 1; } } list.add(str.substring(start)); int splitLength = list.size(); String[] result = new String[splitLength]; for (int i = 0; i < splitLength; i++) { result[i] = list.get(i).trim(); } return result; } public static String[] splitTrim(String str) { return splitTrim(str, ","); } }