自定义工具类之“分割所有类型的字符串”
/** * <p>默认根据,, \t\n\r分隔符分隔出list</p> * * <pre> * tokenizeToStringArray(null) = null * tokenizeToStringArray("www.baidu.com") = [www.baidu.com] * tokenizeToStringArray("a,b,c") = [a, b, b] * </pre> * @param str the String to check, may be null * @return an list of parsed Strings, null if null String input */ public static List<String> tokenizeToStringList(String str) { return tokenizeToStringList(str, ",, \t\n\r"); }
被调用方法
/** * <p>根据分隔符分隔出list</p> * * <pre> * tokenizeToStringArray(null, " \t\n\r\f") = null * tokenizeToStringArray("www.baidu.com", ".b") = [www, aidu, com] * tokenizeToStringArray("a,b,c", ",, \t\n\r") = [a, b, b] * </pre> * @param str the String to check, may be null * @param delimiters the delimiter characters, assembled as a {@code String} * @return an list of parsed Strings, null if null String input */ public static List<String> tokenizeToStringList(String str, String delimiters) { if (str == null) { return null; } StringTokenizer st = new StringTokenizer(str, delimiters); List<String> tokens = new ArrayList<String>(); while (st.hasMoreTokens()) { String token = st.nextToken().trim(); if (token.length() > 0) { tokens.add(token); } } return tokens; }
标签:分割,return,String,自定义,www,tokenizeToStringArray,str,字符串,null From: https://www.cnblogs.com/saoge/p/17016326.html