s-day02-Set接口的特点
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package com.inmind.set02;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set集合是Collection集合的子接口,所以它拥有Collection接口的所有功能.
|
||||||
|
Set接口的特点:
|
||||||
|
1.存取无序(怎么存的不一定怎么取)
|
||||||
|
2.没有索引
|
||||||
|
3.不能重复
|
||||||
|
|
||||||
|
Set接口的实现类:
|
||||||
|
HashSet LinkedHashSet
|
||||||
|
*/
|
||||||
|
public class SetDemo06 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//Set集合的三个特点(Set接口多态写法)
|
||||||
|
//父接口引用指向实现类对象
|
||||||
|
Set<String> sets = new HashSet();
|
||||||
|
sets.add("刘备");
|
||||||
|
sets.add("关羽");
|
||||||
|
sets.add("张飞");
|
||||||
|
System.out.println(sets);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user