Here you can find the source of splitString(String toSplit, String delimiter)
Parameter | Description |
---|---|
toSplit | the string to split |
delimiter | to split the string up with |
null
if the delimiter wasn't found in the given input String
public static List<String> splitString(String toSplit, String delimiter)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**//from ww w . j a v a 2 s . c om * Split a String at the first occurrence of the delimiter. * Does not include the delimiter in the result. * @param toSplit the string to split * @param delimiter to split the string up with * @return a two element array with index 0 being before the delimiter, and * index 1 being after the delimiter (neither element includes the delimiter); * or <code>null</code> if the delimiter wasn't found in the given input String */ public static List<String> splitString(String toSplit, String delimiter) { if (!hasLength(toSplit) || !hasLength(delimiter)) { return Collections.emptyList(); } return Arrays.asList(toSplit.split(delimiter)); } /** * Check that the given CharSequence is neither <code>null</code> nor of length 0. * Note: Will return <code>true</code> for a CharSequence that purely consists of whitespace. * <p><pre> * StringUtils.hasLength(null) = false * StringUtils.hasLength("") = false * StringUtils.hasLength(" ") = true * StringUtils.hasLength("Hello") = true * </pre> * @param str the CharSequence to check (may be <code>null</code>) * @return <code>true</code> if the CharSequence is not null and has length */ public static boolean hasLength(CharSequence str) { return (str != null && str.length() > 0); } }