StringUtils 和 MapUtil 的使用
/**
* 2021/2/13
* 把集合转化成指定形式的字符串 package org.springframework.util;
*/
@Test
void test9(){
List<String> list = Arrays.asList("a", "b", "c");
System.out.println("list: "+list);
String str = StringUtils.collectionToDelimitedString(list, "--");//指定分隔符
System.out.println("str : "+str);
//结果
// list: [a, b, c]
//str : a--b--c
//Apache Commons的StringUtils =====>> String str = StringUtils.join(list.toArray(), ",");
}
/**
* 排序Map
*
* MapUtil package cn.hutool.core.map;
* 工具包
* <dependency>
* <groupId>cn.hutool</groupId>
* <artifactId>hutool-all</artifactId>
* <version>5.4.7</version>
* </dependency>
*/
@Test
void test10(){
HashMap<String, String> map = new HashMap<>();
map.put("A","李明");
map.put("C","张飞");
map.put("E","关羽");
map.put("D","明明");
map.put("B","宋江");
TreeMap<String, String> sort = MapUtil.sort(map);
System.out.println(sort);
//结果: {A=李明, B=宋江, C=张飞, D=明明, E=关羽}
}