Set courseSet = new HashSet();
Set<String> courseSet1 = new HashSet<String>();
Set<String> h = new HashSet<String>(Arrays.asList("a", "b"));
List和Set集合是可以像String类型那样声明和初始化的,区别在于Set本身是一个接口,只能实例化它的实现类,比如上面贴的HashSet。像第三行那样声明并初始化使用也可以。
public class Student{
public String id;
public String name;
public Set courses;
public Student(String id, String name){
this.id = id;
this.name = name;
this.courses = new HashSet();
}
}
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦