为什么这个是工具是这个依赖地址:
https://blog.youkuaiyun.com/weixin_44458365/article/details/119448509
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--或者-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.1</version>
<scope>compile</scope>
</dependency>
方法:
实验室:
Emp empIns = new Emp().setDepartId(1L).setDepartName("molizhuangquanquan").setEmail("94655718@qq.com").setDepartNumber(23);
Emp empIn = new Emp().setDepartId(1l).setDepartName("chenpi1").setEmail("94655718@qq.com").setDepartNumber(10);
Emp empInss = new Emp().setDepartId(2l).setDepartName("chenpi1").setEmail("94655718@qq.com").setDepartNumber(10);
List<Emp> empList1 = Arrays.asList(empIn, empIns);
List<Emp> empList2 = Arrays.asList( empInss);
HashMap<Long, List<Emp>> hashMaop = new HashMap<>();
hashMaop.put(1L, empList1);
hashMaop.put(2L, empList2);
String[] arrayA = new String[] { "1", "2", "3", "4"};
String[] arrayB = new String[] { "3", "4", "5", "6" };
List<String> listA = Arrays.asList(arrayA);
List<String> listB = Arrays.asList(arrayB);
Properties properties = Environment.getProperties();
MultiValueMap<Long, Emp> objectObjectMultiValueMap = CollectionUtils.toMultiValueMap(hashMaop);
System.out.println("objectObjectMultiValueMap = " + objectObjectMultiValueMap);
// objectObjectMultiValueMap = {1=[Emp(departId=1, departName=chenpi1, email=94655718@qq.com, departNumber=10), Emp(departId=1, departName=molizhuangquanquan, email=94655718@qq.com, departNumber=23)], 2=[Emp(departId=2, departName=chenpi1, email=94655718@qq.com, departNumber=10)]}
List<Integer> intList = new ArrayList<>();
CollectionUtils.mergeArrayIntoCollection(arrayA, intList);
System.out.println("intList = " + intList);
// intList = [1, 2, 3, 4]
List<Integer> objects = (List<Integer>) CollectionUtils.arrayToList(arrayA);
System.out.println("objects = " + objects);
// objects = [1, 2, 3, 4]
List<Long> lonList = (List<Long>) CollectionUtils.arrayToList(arrayA);
System.out.println("lonList = " + lonList);
//lonList = [1, 2, 3, 4]
LinkedHashMap<Object, Object> linkedHashMap = CollectionUtils.newLinkedHashMap(10);
CollectionUtils.mergePropertiesIntoMap(properties, new HashMap<>());
boolean b1 = CollectionUtils.containsInstance(intList, 1);
System.out.println("b1 = " + b1);
// b1 = false
String firstMatch = CollectionUtils.findFirstMatch(listB, listA);
System.out.println("firstMatch = " + firstMatch);
// firstMatch = 3
String valueOfType = CollectionUtils.findValueOfType(listA, String.class);
System.out.println("valueOfType = " + valueOfType);
// valueOfType = null
boolean b = CollectionUtils.hasUniqueObject(listA);
System.out.println("b = " + b);
// b = false
Class<?> afd = CollectionUtils.findCommonElementType(empList1);
System.out.println("afd = " + afd);
// afd = class com.example.integrateSpringdemo.entity.Emp
String s = CollectionUtils.firstElement(listA);
System.out.println("s = " + s);
// s = 1
String s1 = CollectionUtils.lastElement(listA);
System.out.println("s1 = " + s1);
// s1 = 4
Vector<String> strings = new Vector<>();
strings.add("1");
strings.add("2");
strings.add("3");
strings.add("4");
Enumeration<String> enm = strings.elements();
boolean contains = CollectionUtils.contains(enm, 1);
System.out.println("contains = " + contains);
// contains = false
说句心里话,还不如我用java自带的去处理。