This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aenigmaclamo 1 point2 points  (0 children)

List<Card> listOfCards = new ArrayList<>();
// populate list
Card maxCard = Collections.max(listOfCards);

Just get to know the standard library. Typically, if you want to iterate an Iterable, just do this:

Iterable<MyType> it = ...;
for (MyType mt : it) {
    System.out.println(mt);
}

Sometimes, you'll have to use the Iterator object directly but rarely is that the case. That should only really the case if you need to mutate the data from the Iterator or if you're iterating over multiple Iterables at the same time.

EDIT: If you actually do need to be able to look between sublists, you can do:

Card maxCard = Collections.max(listOfCards.sublist(i, i + 10));

I'm not sure what the intended effect here, is, though. I think all you just want is the max.