@Test public void testSplit(){ String[] split = Util.split("", ','); the(split.length).shouldBeEqual(0); split = Util.split(" ", ','); the(split.length).shouldBeEqual(1); the(split[0]).shouldBeEqual(""); split = Util.split("a..b", '.'); the(split.length).shouldBeEqual(2); the(split[0]).shouldBeEqual("a"); the(split[1]).shouldBeEqual("b"); split = Util.split("a . . b", '.'); the(split.length).shouldBeEqual(3); the(split[0]).shouldBeEqual("a"); the(split[1]).shouldBeEqual(""); the(split[2]).shouldBeEqual("b"); split = Util.split(" Hello, Dolly, my darling ", ','); the(split.length).shouldBeEqual(3); the(split[0]).shouldBeEqual("Hello"); the(split[1]).shouldBeEqual("Dolly"); the(split[2]).shouldBeEqual("my darling"); split = Util.split("/blog/*items", '/'); the(split.length).shouldBeEqual(2); the(split[0]).shouldBeEqual("blog"); the(split[1]).shouldBeEqual("*items"); }
public static String[] split(String input, String delimiters) { if (input == null) { throw new NullPointerException("input cannot be null"); } List<String> tokens = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(input, delimiters); while(st.hasMoreTokens()) { tokens.add(st.nextToken().trim()); } return tokens.toArray(new String[tokens.size()]); }
Util { public static String[] split(String input, String delimiters) { if (input == null) { throw new NullPointerException("input cannot be null"); } List<String> tokens = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(input, delimiters); while(st.hasMoreTokens()) { tokens.add(st.nextToken().trim()); } return tokens.toArray(new String[tokens.size()]); } }
Util { public static String[] split(String input, String delimiters) { if (input == null) { throw new NullPointerException("input cannot be null"); } List<String> tokens = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(input, delimiters); while(st.hasMoreTokens()) { tokens.add(st.nextToken().trim()); } return tokens.toArray(new String[tokens.size()]); } private  Util(); }
Util { public static String[] split(String input, String delimiters) { if (input == null) { throw new NullPointerException("input cannot be null"); } List<String> tokens = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(input, delimiters); while(st.hasMoreTokens()) { tokens.add(st.nextToken().trim()); } return tokens.toArray(new String[tokens.size()]); } private  Util(); static byte[] readResourceBytes(String resourceName); static String readResource(String resourceName); static String readResource(String resourceName, String charset); static String readFile(String fileName); static String readFile(String fileName, String charset); static void closeQuietly(AutoCloseable autoCloseable); static void closeQuietly(AutoCloseable ... autoCloseable); static void closeQuietly(List<T> autoCloseable); static String read(InputStream in); static String read(InputStream in, String charset); static byte[] bytes(InputStream in); static byte[] read(File file); static List<String> getResourceLines(String resourceName); static boolean blank(Object value); static boolean empty(Object[] array); static boolean empty(Collection<?> collection); static String join(String[] array, String delimiter); static String[] split(String input, String delimiters); static String[] split(String input, char delimiter); static String join(Collection<?> collection, String delimiter); static void join(StringBuilder sb, Collection<?> collection, String delimiter); static void join(StringBuilder sb, Object[] array, String delimiter); static void repeat(StringBuilder sb, String str, int count); static void joinAndRepeat(StringBuilder sb, String str, String delimiter, int count); static void saveTo(String path, InputStream in); static String getCauseMessage(Throwable throwable); static String getStackTraceString(Throwable throwable); static void saveTo(String path, byte[] content); static String toBase64(byte[] input); static byte[] fromBase64(String input); String[] arr(String ... params); static Properties readProperties(String fileOrResource); static boolean createTree(Path path); static void recursiveDelete(Path directory); }
Util { public static String[] split(String input, String delimiters) { if (input == null) { throw new NullPointerException("input cannot be null"); } List<String> tokens = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(input, delimiters); while(st.hasMoreTokens()) { tokens.add(st.nextToken().trim()); } return tokens.toArray(new String[tokens.size()]); } private  Util(); static byte[] readResourceBytes(String resourceName); static String readResource(String resourceName); static String readResource(String resourceName, String charset); static String readFile(String fileName); static String readFile(String fileName, String charset); static void closeQuietly(AutoCloseable autoCloseable); static void closeQuietly(AutoCloseable ... autoCloseable); static void closeQuietly(List<T> autoCloseable); static String read(InputStream in); static String read(InputStream in, String charset); static byte[] bytes(InputStream in); static byte[] read(File file); static List<String> getResourceLines(String resourceName); static boolean blank(Object value); static boolean empty(Object[] array); static boolean empty(Collection<?> collection); static String join(String[] array, String delimiter); static String[] split(String input, String delimiters); static String[] split(String input, char delimiter); static String join(Collection<?> collection, String delimiter); static void join(StringBuilder sb, Collection<?> collection, String delimiter); static void join(StringBuilder sb, Object[] array, String delimiter); static void repeat(StringBuilder sb, String str, int count); static void joinAndRepeat(StringBuilder sb, String str, String delimiter, int count); static void saveTo(String path, InputStream in); static String getCauseMessage(Throwable throwable); static String getStackTraceString(Throwable throwable); static void saveTo(String path, byte[] content); static String toBase64(byte[] input); static byte[] fromBase64(String input); String[] arr(String ... params); static Properties readProperties(String fileOrResource); static boolean createTree(Path path); static void recursiveDelete(Path directory);  }