guava Splitterとjava内蔵stringのsplit方法の違いは何ですか.
1136 ワード
JAvaに内蔵されているものは空の内容を無視し、guava Splitterは無視しません.あるいは自由に選択する無視することができる.
/**
* {@code Splitter} {@code Joiner} map , web spring mvc .
*
* get url pos form . .
*
* @author doctor
*
* @since 2015 3 14 9:00:17
*/
..............
@Test
public void test_string_split() {
String[] split = "a,b,,".split(","); // java
assertThat(split, equalTo(Lists.newArrayList("a", "b").toArray()));
}
@Test
public void test_guava_Splitter() {
List<String> splitToList = Splitter.on(",").splitToList("a,b,,");//guava
assertThat(splitToList, equalTo(Lists.newArrayList("a", "b", "", "")));
}
@Test
public void test_guava_Splitter_omitEmptyStrings() {
// , java ,
List<String> splitToList = Splitter.on(",").omitEmptyStrings().trimResults().splitToList("a,b,,");
assertThat(splitToList, equalTo(Lists.newArrayList("a", "b")));
}