init
This commit is contained in:
42
day01/src/com/inmind/TreeSetDemo1.java
Normal file
42
day01/src/com/inmind/TreeSetDemo1.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.inmind;
|
||||
|
||||
import com.inmind.test07.Student;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class TreeSetDemo1 {
|
||||
public static void main(String[] args) {
|
||||
TreeSet<Student> treeSet = new TreeSet<>(new Comparator<Student>() {
|
||||
|
||||
@Override
|
||||
public int compare(Student o1, Student o2) {
|
||||
return o2.getId() - o1.getId();
|
||||
}
|
||||
});
|
||||
Student s1 = new Student();
|
||||
s1.setId(1);
|
||||
Student s2 = new Student();
|
||||
s2.setId(3);
|
||||
Student s3 = new Student();
|
||||
s3.setId(5);
|
||||
treeSet.add(s1);
|
||||
treeSet.add(s2);
|
||||
treeSet.add(s3);
|
||||
System.out.println(treeSet);
|
||||
|
||||
TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
|
||||
@Override
|
||||
public int compare(Student o1, Student o2) {
|
||||
return o2.getId() - o1.getId();
|
||||
}
|
||||
});
|
||||
treeMap.put(s1, "<UNK>");
|
||||
treeMap.put(s2, "<UNK>");
|
||||
treeMap.put(s3, "<UNK>");
|
||||
|
||||
System.out.println(treeMap);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user