split

 //String[] idArr =  StringUtils.split(idStr, delimiter);
       String[] idArr =  idStr.split(delimiter);
 

第一个是用APACHE或者SPRING的
第二个是用JDK的
如果IDSTR不包含分割符,处理结果是不一样的

spring的 找不到会报错,而jdk的不会报错

/**
	 * 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 String[] split(String toSplit, String delimiter) {
		if (!hasLength(toSplit) || !hasLength(delimiter)) {
			return null;
		}
		int offset = toSplit.indexOf(delimiter);
		if (offset < 0) {
			return null;
		}
		String beforeDelimiter = toSplit.substring(0, offset);
		String afterDelimiter = toSplit.substring(offset + delimiter.length());
		return new String[] {beforeDelimiter, afterDelimiter};
	}
  注:用apathe 的包 会使结果散掉,

String[] idArr =  StringUtils.split("CUSTOMER_XSG", "_OR_");
得到的结果是 CUST
ME
XSG

你可能感兴趣的:(split)