stream allMatch判断两个集合是否相同
stream的allMatch方法用于判断集合中的所有元素是否满足特定的条件,而不是用于判断两个集合是否相同。若要判断两个集合是否相同,可以使用equals方法。
示例代码如下:
List<Integer> list1 = Arrays.asList(1, 2, 3);
List<Integer> list2 = Arrays.asList(1, 2, 3);
boolean result = list1.equals(list2);
System.out.println(result); // 输出true
以上代码通过equals方法判断两个集合是否相同,输出结果为true。
原文地址: https://www.cveoy.top/t/topic/ihha 著作权归作者所有。请勿转载和采集!