public class Student {
public String Name;
public Integer Age;
public Student(String name, Integer age) {
Name = name;
Age = age;
}
}
public class SetTest {
public List<Student> studentList;
public Set<Student> studentSet;
public SetTest() {
studentSet = new HashSet<Student>();
studentList = new ArrayList<>();
//setRole = new TreeSet<Role>();
}
public static void main(String args[]){
int i;
SetTest setTest = new SetTest();
Random rand = new Random(23);
for(i = 0;i<10;i++)
{
Student rl = new Student( ""+i,18+rand.nextInt(3));
setTest.studentSet.add(rl);
}
for (Student st:setTest.studentSet) {
setTest.studentList.add(st);
System.out.println(st);
}
/*Collections.sort(setTest.listRole, new Comparator<Role>() {
@Override
public int compare(Role o1, Role o2) {
return o1.Name.compareTo(o2.Name);
}
});*/
Collections.sort(setTest.studentList,comparing((Student role)->role.Name));
Collections.sort(setTest.studentList,(Student a1,Student a2)->{return a2.Name.compareTo(a1.Name);});
System.out.println("List order");setTest.studentList.stream().forEach(System.out::println);
public class Student { public String Name; public Integer Age; public Student(String name, Integer age) { Name = name; Age = age; }}public class SetTest { pub...