File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
SandBox/src/com/rakitov/sandbox/comparators Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .rakitov .sandbox .comparators ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .Collections ;
5+ import java .util .List ;
6+
7+ /**
8+ * @author Stanislav Rakitov
9+ */
10+ public class Woman implements Comparable <Woman >{
11+ private final int age ;
12+
13+ public Woman (int age ) {
14+ this .age = age ;
15+ }
16+
17+ @ Override
18+ public int compareTo (Woman woman ) {
19+ return this .age - woman .age ;
20+ }
21+
22+ public static void main (String [] args ) {
23+ List <Woman > women = new ArrayList <>();
24+ women .add (new Woman (57 ));
25+ women .add (new Woman (27 ));
26+ women .add (new Woman (17 ));
27+ women .add (new Woman (43 ));
28+
29+ System .out .println ("Before sort" );
30+ women .forEach (System .out ::println );
31+ System .out .println ("\n After sort" );
32+ Collections .sort (women );
33+ women .forEach (System .out ::println );
34+
35+ }
36+
37+ @ Override
38+ public String toString () {
39+ return "Woman age of " + age ;
40+ }
41+ }
42+
43+
You can’t perform that action at this time.
0 commit comments