The solution can be optimized in following way: Firstly, use a private inner class as the scope for the fields is to be the enclosing class TestPeople so as the implementation of class People won't get exposed to outer world. This can be understood in terms of creating an APIthat expects a sorted list of people Secondly, using the Lamba expression(java 8) which reduces the code, hence development effort

10mm scaleratio

10mm Linear Scale, in X & Y axis, with 100 divisions in 0.10mm increments and -5 to -1 and +1 to +5 Labeling in both axis

10mm scalewargaming

I believe it has to do something with the casting in the compare method but I was playing around with it and still could not find the solution

10mmminiatures manufacturers

You're confusing the two by trying to sort a Comparator (which is again why it doesn't make sense that Person implements Comparator). Again, to use Collections.sort, you need one of these to be true:

Here's an example of a Comparator that will work for any zero arg method that returns a Comparable. Does something like this exist in a jdk or library?

You will then find that your code doesn't even compile!! That would be a good thing, because there IS something wrong with the code (Person does not implements Comparable), but because you used raw type, the compiler didn't check for this, and instead you get a ClassCastException at run-time!!!

A Comparator can also be defined in addition, but People implements Comparator is not the right way of doing things.

You want to implement Comparable, not Comparator. You need to implement the compareTo method. You're close though. Comparator is a "3rd party" comparison routine. Comparable is that this object can be compared with another.

10mm scaleminiatures

Java 8 added a new way of making Comparators that reduces the amount of code you have to write, Comparator.comparing. Also check out Comparator.reversed

By continuing to browse our website, you’re agreeing to the use of cookies. Please review our privacy policy and terms of use for more details.

If you are using Java 7 or below then you can use a comparator for customized sorting order by implementing compare method.