import com.google.common.base.Splitter;
public class GuavaSplitterExample {
public static void main(String[] args) {
String str = "a,,b, c,,,d";
Iterable result = Splitter.on(',')
.split(str);
System.out.println("--start--");
for(String s: result){
System.out.println(s);
}
System.out.println("--end--");
}
}
String str = "a,,b, c,,,d";
Iterable result = Splitter.on(',')
.omitEmptyStrings()
.split(str);
String str = "a,,b, c,,,d";
Iterable result = Splitter.on(',')
.trimResults()
.omitEmptyStrings()
.split(str);
String str = "a,,b,c1,,,d2";
Iterable result = Splitter.on(',')
.trimResults(CharMatcher.DIGIT)
.omitEmptyStrings()
.split(str);
–end–
下载包: