引入依赖

<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>



fox.风

案例 数组 拼接(连接)成 字符串

		//创建 map xx
Map<Long,String > xx= Maps.newHashMap();
xx.put(1L,"ssss");
xx.put(2L,"bbbbb");
//创建 map xx2
Map<Long,String > xx2= Maps.newHashMap();
xx2.put(3L,"ssss");
xx2.put(4L,"bbbbb");
//创建数组 aooList
List<String> aooList = Lists.newArrayList(xx.values());
//把  xx2 所有值 存入数组 xx2.values()
//输出
log.info("at ={}",aooList);
//把 List 数组 用 ,  号 拼接(连接)成 字符串，并跳过 null 值
String str= Joiner.on(",").skipNulls().join(aooList);
log.info("join str ={}",str);


at =[ssss, bbbbb, ssss, bbbbb]
join str =ssss,bbbbb,ssss,bbbbb


案例 字符串 分割成数组

		String strArr = "ssss,bbbbb,ssss,,bbbbb";
// 自带分割
String[] arr1 = strArr.split(",");
//转换为 list ,注意这个list 不能再添加原素，否则报错
List<String> list2 = Arrays.asList(arr1);
log.info("List arr1 ={}", list2);
//转换为 list，注意这个list 可以再添加原素
List<String> list3 = Lists.newArrayList(Arrays.asList(arr1));
//转换为 list，注意这个list 可以再添加原素
List<String> list4 = new ArrayList<>(Arrays.asList(arr1));
//分割，去除 空值
Iterable split = Splitter.on(",").trimResults().omitEmptyStrings().split(strArr);
log.info(" Iterable split ={}", split);
//转换为 list
List<String> list = Lists.newArrayList(split);
log.info(" List list ={}", list);
// List<String>  转换 为long[]
long[] array =list.stream().mapToLong(t->t.longValue()).toArray();


List arr1 =[ssss, bbbbb, ssss, , bbbbb]
Iterable split =[ssss, bbbbb, ssss, bbbbb]
List list =[ssss, bbbbb, ssss, bbbbb]


07-30 2071

07-25 1万+
08-02 1952
03-22 2万+
04-14 2万+
04-03 1343
02-22 4167
06-02 4226
01-16 649
03-31 1375
03-03 30