What is the difference between guava Splitter and the split method of Java's built-in string.

Source: Internet
Author: User

Java built-in ignores empty content, guava splitter is not ignored. Or you can freely choose to ignore.

/** * {@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")));    }

What is the difference between guava Splitter and the split method of Java's built-in string.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.