在setTest构造器初始化的时候,为什么不使用Hashset<>呢???详细里有代码
在setTest构造器初始化的时候,为什么不使用Hashset<>呢???
public SetTest(){
this.courseToSelect=new HashSet<Course>();
}
在setTest构造器初始化的时候,为什么不使用Hashset<>呢???
public SetTest(){
this.courseToSelect=new HashSet<Course>();
}
2017-06-08
package jhetext;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Cou {
static List <Cou>list;
static Set <Cou>set;
String sno,name;
public Cou(String sno,String name){
this.sno=sno;
this.name=name;
}
public Cou(){
this.list=new ArrayList<Cou>();
Cou cou1=new Cou("1","aa");
Cou cou2=new Cou("2","bb");
Cou cou3=new Cou("3","cc");
Cou cou4=new Cou("4","dd");
Cou cou5=new Cou("5","ee");
list.add(cou1);
list.add(cou2);
list.add(cou3);
list.add(cou4);
list.add(cou5);
for(Cou c:list){
System.out.println(c.sno+" "+c.name);
}
}
public static void main(String[] args) {
set=new HashSet();
Cou n=new Cou();
Scanner scanner=new Scanner(System.in);
for(int i=0;i<3;i++){
String s=scanner.next();
for(Cou c:list){
if(c.sno.equals(s)){
set.add(c);
}
}
}System.out.println("set:");
for(Cou c:set){
System.out.println(c.sno+" "+c.name);
}
}
}
举报