我有一个返回集合集合的方法。 以下是我的意思:
public static HashSet methodName(){
HashSet c= new HashSet();
c.add(x); //x is a HashSet of number
c.add(y); //y is a Hashset of numbers
return c;
}
方法返回集合后,我将其输入到数组列表中
ArrayList<HashSet> xxx= new ArrayList<Hashset>();
y=methodName();
xxx.add(y);
该方法被调用了几次,每次我将一组组的集合输入到数组列表中。
我的问题是。现在我想遍历 arraylist 并找到包含最少数量集合的集合。我怎么做?非常感谢。任何帮助将不胜感激。
最佳答案
size()
方法给出 HashSet
的基数.简单地写一个 Comparator<HashSet>
并使用 Collections.max()
.
关于Java编程帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4300699/