我目前在迭代集合时遇到了一个问题。当我声明字段和构造函数,并尝试进入我的方法来迭代集合并打印出元素时,出现了以下错误。
类型不兼容-找到java.util.Iterator(Lot)但需要java.util.Iterator (java.lang.String)
这是我的代码。
public class Auction
{
// The list of Lots in this auction.
private ArrayList<Lot> lots;
// The number that will be given to the next lot entered
// into this auction.
private int nextLotNumber;
/**
* Create a new auction.
*/
public Auction()
{
lots = new ArrayList<Lot>();
nextLotNumber = 1;
}
public void close ()
{
Iterator<String> it = lots.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
}发布于 2010-11-23 21:24:11
尝尝这个
public void close ()
{
Iterator<Lot> it = lots.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}https://stackoverflow.com/questions/4256427
复制相似问题