guava教程——Joiner、Splitter
guava是goog1e开源的一套针对java api的扩展工具包,里面包含很多非常实用的方法,在工作中可以提高我们的编码效率; 1.Joiner 将集合按指定字符拼接成字符串; private final List<String> stringList = Arrays.asList( "tom","jack","bob"); private final List<String> stringListWithNullValue = Arrays.asList( "tom","jack","bob",null,"rose"); @Test public void testJoin(){ String join = Joiner.on("#").join(stringList); assertThat(join,equalTo("tom#jack#bob")); } // 跳过list中的null @Test public void testJoinOnJoinSkipNull(){ String join = Joiner.on("#").skipNulls().join(stringListWithNullValue); assertThat(join,equalTo("tom#jack#bob#rose")); } // 替换null为指定字符 @Test public