Here you can find the source of split(String input, String... delimiters)
Parameter | Description |
---|---|
input | a parameter |
delimiters | a parameter |
public static List<String> split(String input, String... delimiters)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**// www . j a v a 2 s . c om * splits the string based on the given delimiters. * * * @param input * @param delimiters * @return */ public static List<String> split(String input, String... delimiters) { if (input == null) return null; String str = input; List<String> list = new ArrayList<String>(); String delim = delimiters[0]; for (int i = 1; i < delimiters.length; i++) { str = str.replaceAll(delimiters[i], delim); } String[] tmp = str.split(delim); for (int i = 0; i < tmp.length; i++) { list.add(tmp[i].trim()); } return list; } /** * will trim off the front and back of the string. * * if trim = " " then it is the same as str.trim() * * @param input * @param trim * @return */ public static String trim(String input, String trim) { if (input == null || trim == null || trim.isEmpty()) return input; String tmp = input; while (tmp.startsWith(trim)) { tmp = tmp.substring(trim.length()); } while (tmp.endsWith(trim)) { tmp = tmp.substring(0, tmp.length() - trim.length()); } return tmp; } }