/java/

Guava split and never null

2014-05-30 00:16:15

    @Test
    public void splitTest() {

        Iterable

<string> split = Splitter.on(',')
                .trimResults()
                .omitEmptyStrings()
                .split("01.jpg,,02.jpg,     03.jpg,,,99.jpg");

        for (String s : split) {
            System.out.println(s);
        }
    }

    @Test
    public void neverNullTest() {
        Integer _default = 1;
        Integer userId = 1;
//      instead of this:  Integer id = userId == null ? _default : userId; you can use this:
        Integer id = Objects.firstNonNull(userId, _default);
        System.out.print(id);
    }
<dependency>
<groupid>com.google.guava</groupid>
<artifactid>guava</artifactid>
<version>17.0</version>
</dependency>