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);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Students cannot be resolved
Student cannot be resolved to a type
Student cannot be resolved to a type
Student cannot be resolved to a type
Student cannot be resolved to a type
students cannot be resolved
students cannot be resolved
students cannot be resolved
students cannot be resolved at com.testSortedSet.main(testSortedSet.java:19) 怎么加Student类?使它可以运行
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);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Students cannot be resolved
Student cannot be resolved to a type
Student cannot be resolved to a type
Student cannot be resolved to a type
Student cannot be resolved to a type
students cannot be resolved
students cannot be resolved
students cannot be resolved
students cannot be resolved at com.testSortedSet.main(testSortedSet.java:19) 怎么加Student类?使它可以运行
new Student("John","Lennon",14),
new Student("Karl","Marx",15),
new Student("Groucho","Bush",12),
new Student("Oscar","Grouch",13)
};class Student{
private String a;
private String b;
int c;
public Student(String a , String b , int c){ this.a = a;
this.b = b;
this.c = c; }}
System.out.println("first:"+firstst);
连这个类都没,还强制转换类型,你下面全错了,