Junilu Lacar wrote:
Omkar Shetkar wrote:Consider implementing Comparable interface for FacebookUser class. Compare friends list size in compareTo() method.
Zach's suggestion to use a Comparator is the better way to go, in my opinion. The semantics of Comparable are narrower and are better suited for comparing things based on more intrinsic attributes. A Comparator has much looser semantics and is better suited for more arbitrary criteria. @OP wants to order the users according to the number of friends they have. This fits better with my idea of what a Comparator would be for.
Junilu Lacar wrote:Despite how most IDEs try to "help" by telling you that you forgot to close a Scanner, you really shouldn't be closing a Scanner that's tied to System.in -- those warnings can be safely ignored or suppressed with an @SuppressWarnings("resource")
So, there's really no need to wrap that code in a try-finally block.