-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddf19f2
commit a0b9877
Showing
3 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package misc; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class Sorting { | ||
|
||
|
||
public static <T extends Comparable<? super T>> void sort(List<T> list) { ... } | ||
|
||
|
||
/*public interface Comparator<T> { | ||
int compare(T o1, T o2); | ||
}*/ | ||
|
||
public static void main(String[] args) { | ||
{ | ||
List<Zoo.Dog> l = new ArrayList<>(); | ||
l.add(new Zoo.Dog(20, "mio")); | ||
l.add(new Zoo.Dog(29, "mio")); | ||
l.add(new Zoo.Dog(28, "mio")); | ||
sort(l); | ||
|
||
|
||
|
||
|
||
Collections.sort(l, new Comparator<>() { | ||
@Override | ||
public int compare(Zoo.Animal a, Zoo.Animal b) { | ||
return a.weight - b.weight; | ||
} | ||
}); | ||
} | ||
{ | ||
List<String> l = List.of("ciao", "pippo", "gigio", "byebye"); | ||
Collections.sort(l, new Comparator<>() { | ||
public int compare(String a, String b) { | ||
return b.length() - a.length(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters