源字符串有n个分隔符,生成的List的size就为n+1,没有内容的元素就为空串("")
/**
* 分解字符串
*
* @param source
* @param delimiter
* @return
*/
public static List<String> splitByStr(String source, String delimiter) {
ArrayList<String> list = new ArrayList<String>();
if (source == null || source.length() == 0) {
return list;
}
if (delimiter == null || delimiter.length() == 0) {
list.add(source);
return list;
}
int fromIndex = 0;
int delimiterLength = delimiter.length();
do {
int index = source.indexOf(delimiter, fromIndex);
if (index == fromIndex) {
list.add("");
} else if (index == -1) {
list.add(source.substring(fromIndex, source.length()));
break;
} else {
list.add(source.substring(fromIndex, index));
}
fromIndex = index + delimiterLength;
} while (true);
return list;
}
分享到:
相关推荐
正则表达式.rar正则表达式.rar正则表达式.rar正则表达式.rar
正则表达式 范例.txt正则表达式 范例.txt正则表达式 范例.txt正则表达式 范例.txt
JavaScript验证正则表达式大全.txtJavaScript验证正则表达式大全.txtJavaScript验证正则表达式大全.txtJavaScript验证正则表达式大全.txtJavaScript验证正则表达式大全.txtJavaScript验证正则表达式大全....
Regular_Expression正则表达式手册.zipRegular_Expression正则表达式手册.zipRegular_Expression正则表达式手册.zipRegular_Expression正则表达式手册.zip
正则表达式.rar正则表达式.rar正则表达式.rar正则表达式.rar正则表达式.rar正则表达式.rar正则表达式.rar正则表达式.rar
常用正则表达式大全.txt常用正则表达式大全.txt常用正则表达式大全.txt常用正则表达式大全.txt常用正则表达式大全.txt
电话号码正则... 3 手机号码正则表达式... 4 使用正则表达式实现删除字符串中的空格:... 4 限制文本框只能输入数字和小数点等等... 5 替换小数点前内容为指定内容... 5 只匹配中文的正则表达式... 5 返回字符串的...
正则表达式chm.zip正则表达式chm.zip
java,正则表达式,详解,java正则表达式,PDF
正则表达式大全.doc 正则表达式大全.doc
Java正则表达式详解.pdf Java正则表达式详解.pdf
JavaScript_正则表达式语法.doc
正则表达式大全.pdf。正则表达式大全.pdf。
正则表达式.doc正则表达式.doc正则表达式.doc正则表达式.doc正则表达式.doc正则表达式.doc正则表达式.doc正则表达式.doc正则表达式.doc
常用的正则表达式...............要用的话可以考虑下载
“正则表达式”教程.rar “正则表达式”教程.rar “正则表达式”教程.rar “正则表达式”教程.rar “正则表达式”教程.rar “正则表达式”教程.rar
正则表达式.txt,希望对大家有所帮助,正则表达式.txt,正则表达式.txt
正则表达式文档.docx
正则表达式教程正则表达式教程正则表达式教程正则表达式教程正则表达式教程正则表达式教程正则表达式教程正则表达式教程正则表达式教程
asp.net\C#正则表达式整理+\C#正则表达式整理 .docasp.net\C#正则表达式整理+\C#正则表达式整理 .doc