示例如下:
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> list1 = Arrays.asList("深圳攀峰运","深圳攀峰运","广州博纳德","广州博纳德","广州博纳德","广州博纳德");
List<String> list2 = Arrays.asList("广州博纳德","广州博纳德","深圳攀峰运","深圳攀峰运","深圳攀峰运","深圳攀峰运");
// 方法一:使用 Collections 类的 frequency 方法
boolean isEqual = true;
for (String element : new HashSet<>(list1)) {
if (Collections.frequency(list1, element) != Collections.frequency(list2, element)) {
isEqual = false;
break;
}
}
System.out.println("两个列表的元素是否相等且各自元素数量相等: " + isEqual);
}
}
标签:攀峰运,java,元素,list1,相等,博纳德,frequency
From: https://www.cnblogs.com/linhuaming/p/18178088