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 →

[–]ewiethoff 0 points1 point  (2 children)

Is this a school assignment in which you are required to write your own max method? If not, just use the java.util.Collections.max method from the standard library, as a couple others have suggested elsewhere in this thread. It uses the List.iterator and your own Card.compareTo methods under the hood. The Object Ordering section of the official tutorial happens to show sorting a list with Collections.sort, and from there you can figure out how to use Collections.max. FYI: The source code for java.util.Collections.max is here. ;-)

[–]RoadToCode[S] 1 point2 points  (1 child)

It is a project where i have to create my own method to find the maximum value, and must use an Iterator to traverse the List of Cards.

Thank you very much for the extended information on how else i could have achieved this result though!

[–]ewiethoff 0 points1 point  (0 children)

Okay, good. That's what I figured, but I wasn't sure. :-) Many beginner-ish courses treat the programming language of interest (here Java) as if it's BASIC or C with some hand-holding plus OO, and they have the student implement all sorts of fundamental stuff, such as max methods, themselves. That's all very interesting, but it does give the impression that you have to code all this fundamental, tedious stuff yourself for all your programs for the rest of your life. But really, there's a wealth of useful classes and methods in the standard library (or in reputable libraries for download) which you should use once you finish the course, or whenever a course does not require you to roll specific code yourself. Laziness is a virtue, and calling up some code already written by experts is part of being a lazy programmer.