File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import java .util .Comparator ;
55import java .util .List ;
66
7- // Compare lists by sorting and transfering to strings
8- // We assume that in-place sorting is OK
9-
10- public class CompareListsEx2 {
11-
12- public static boolean compareList (List <String > l1 , List <String > l2 ) {
13-
14- return l1 .toString ().contentEquals (l2 .toString ());
15- }
7+ public class CompareListsEx3 {
168
179 public static void main (String [] args ) {
1810
19- List <String > words = new ArrayList <>();
20- List <String > words2 = new ArrayList <>();
21-
22- words .add ("dog" );
23- words .add ("pen" );
24- words .add ("sky" );
25- words .add ("rock" );
26-
27- words2 .add ("dog" );
28- words2 .add ("pen" );
29- words2 .add ("rock" );
30- words2 .add ("sky" );
31-
32- words .sort (Comparator .naturalOrder ());
33- words2 .sort (Comparator .naturalOrder ());
34-
35- System .out .println (words );
36- System .out .println (words2 );
37-
38- boolean equal = compareList (words , words2 );
39-
40- if (equal ) {
41-
42- System .out .println ("Lists are equal" );
43- } else {
44-
45- System .out .println ("Lists are not equal" );
46- }
4711
4812 }
4913}
You can’t perform that action at this time.
0 commit comments