List使用:
@Test
public void testList(){
List<String> list = Splitter.on("-")
.splitToList("A-B-C");
System.out.println(list);
List<String> list1 = new ArrayList<>(list);
list1.add(null);
list1.add("D");
String s = Joiner.on("@")
.skipNulls() // 如果有null会报错
.join(list1);
System.out.println(s);
}
[A, B, C]
A@B@C@D
Map使用:
@Test
public void testMap(){
Map<String, String> map = Splitter.on("-")
.withKeyValueSeparator("=")
.split("A=1-B=2-C=3");
System.out.println(map);
String s = Joiner.on("@")
.withKeyValueSeparator(":")
.join(map);
System.out.println(s);
}
{A=1, B=2, C=3}
A:1@B:2@C:3