Java编程帮助

Java编程帮助,java,Java,我有一个返回集合集合的方法。 我的意思是: 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 ArrayList<HashSet> xxx= new ArrayList<H

我有一个返回集合集合的方法。 我的意思是:

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

ArrayList<HashSet> xxx= new ArrayList<Hashset>();
y=methodName();
xxx.add(y);
ArrayList xxx=新的ArrayList();
y=methodName();
xxx.加入(y);
该方法会被调用几次,每次我将集合集输入arraylist时


我的问题是。现在我想遍历arraylist并找到包含最少集合的集合。我该怎么做?非常感谢。任何帮助都将不胜感激

size()方法给出了
哈希集的基数。只需编写并使用。

遍历数组的一种简单方法是通过
迭代器。这些在foreach循环中使用,当您知道数组中使用的元素类型时(通过泛型),可以使用foreach循环。您可以在包含
ArrayList的外部
HashSet
中使用它:

for (HashSet set : xxx) {
    // you need to iterate over the elements in your HashSet here and determine which internal Set has the most elements
    for ( Iterator iter = set.iterator(); iter.hasNext();) {
        HashSet innerSet = (HashSet) iter.next();
        // do the size test
     }

}

你能告诉我全部密码吗。如何比较大小
HashSet minimen=null;对于(HashSet currentSet:xxx){if(minimate==null | | | minimate.size()>currentSet.size())minimate=currentSet;}