Here you can find the source of splitString(String s)
public static String[] splitString(String s)
//package com.java2s; /**//from ww w. j a v a 2s . co m * This file is part of SIMPL4(http://simpl4.org). * * Copyright [2014] [Manfred Sattler] <manfred@ms123.org> * * SIMPL4 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. * * SIMPL4 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 SIMPL4. If not, see <http://www.gnu.org/licenses/>. */ import java.util.*; public class Main { private static char[] delimeters = { ' ', '-', '+', ',', '/' }; public static String[] splitString(String s) { if (indexOfAny(s, delimeters) == -1) { String[] sa = new String[1]; sa[0] = s; return sa; } StringTokenizer st = new StringTokenizer(s, " +-,/"); String[] sp = new String[st.countTokens()]; int i = 0; while (st.hasMoreTokens()) { sp[i++] = st.nextToken(); } return sp; } private static int indexOfAny(String str, char[] searchChars) { if (str == null) { return -1; } for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); for (char searchChar : searchChars) { if (searchChar == ch) { return i; } } } return -1; } }