我希望下面的课程中OUTPUT
为3
:
public class Pattern {
public static void main(String[] args) {
String data = "111,577,5099,541,142,
2015-08-01 00:08:42,2015-08-01 06:31:52|
674,898,7061,36,105,2015-08-01 19:28:45,
2015-08-02 14:46:27|948,522,1840,66,889,
2015-08-02 13:04:56,2015-08-02 19:39:57";
if(data.contains("|"))
{
String pattern[] = data.split("|");
System.out.println("the pattern length: "+pattern.length);
}
}
}
输出:
图案长度:180
答案 0 :(得分:4)
字符|
是正则表达式中的特殊字符(split
方法使用正则表达式)
你必须和
一起去String pattern[] = data.split("\\|");
答案 1 :(得分:1)
同样更新你的代码,
String pattern[] = data.split("\\|");