如果数组列表为空,此代码将返回错误。我需要添加代码以避免错误,如果为空则返回 null。谢谢
public Comment findMostHelpfulComment()
{
Iterator<Comment> it = comments.iterator();
Comment best = it.next();
while(it.hasNext())
{
Comment current = it.next();
if(current.getVoteCount() > best.getVoteCount()) {
best = current;
}
}
return best;
}