23,407
社区成员
发帖
与我相关
我的任务
分享 while(in.hasNextLine()){
String text = in.next();
String[] field = text.split(",");
System.out.println(field.length);
}201109290140,507842208552,,,,
201109290104,507842330578,腾讯,,休闲娱乐\游戏\家园,
201109290227,490012727652,手机阅读,手机阅读,休闲娱乐\小说\手机阅读,
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"]
String s = "201109290140,507842208552,,,,";
Iterator<String> it = Splitter.on(",").split(s).iterator();
while (it.hasNext()) {
System.out.println("hah:" + it.next());
}
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
The string "boo:and:foo", for example, yields the following results with these expressions:
Regex Result
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }