4月 142019
 

注意:本文档基于google guava 28 wiki

Joiner

连接器

将字符串拼接

Joiner joiner = Joiner.on("; ").skipNulls();
return joiner.join("Harry", null, "Ron", "Hermione");

返回Harry; Ron; Hermione
skipNulls()方法是直接忽略null,使用useForNull(String)方法可以给定某个字符串来替换null,即

Joiner joiner = Joiner.on("; ").useForNull("替换字符串");

Continue reading »