package com;
import java.util.*;public class testSortedSet {
static final Student students[]={
new Student("John","Lennon",14),
new Student("Karl","Marx",15),
new Student("Groucho","Bush",12),
new Student("Oscar","Grouch",13)};
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List st =Arrays.asList(Students);//这行是什么意思?
SortedSet stSet =new TreeSet(st);//这行是什么意思?
System.out.println(stSet);Student firstst=(Student)stSet.first();
System.out.println("first:"+firstst);Student lastst=(Student)stSet.last();
System.out.println("last:"+lastst);SortedSet headset=stSet.headSet(students[1]);
System.out.println("headSet:"+headset);SortedSet tailset =stSet.tailSet(students[1]);
System.out.println("tainlSet:"+tailset);SortedSet subset =stSet.subSet(students[2], students[0]);
System.out.println("subSet:"+subset);
}
}问题在上面,是什么意思的?
import java.util.*;public class testSortedSet {
static final Student students[]={
new Student("John","Lennon",14),
new Student("Karl","Marx",15),
new Student("Groucho","Bush",12),
new Student("Oscar","Grouch",13)};
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List st =Arrays.asList(Students);//这行是什么意思?
SortedSet stSet =new TreeSet(st);//这行是什么意思?
System.out.println(stSet);Student firstst=(Student)stSet.first();
System.out.println("first:"+firstst);Student lastst=(Student)stSet.last();
System.out.println("last:"+lastst);SortedSet headset=stSet.headSet(students[1]);
System.out.println("headSet:"+headset);SortedSet tailset =stSet.tailSet(students[1]);
System.out.println("tainlSet:"+tailset);SortedSet subset =stSet.subSet(students[2], students[0]);
System.out.println("subSet:"+subset);
}
}问题在上面,是什么意思的?
2.将list对象转换成sortset对象,为后来的排序做准备
SortedSet stSet =new TreeSet(st);//这行是把List形式的st转换成SortedSet的形式