主要方法 import java.util.HashSet; import java.util.Iterator; public class HashSetDemo{ public static void main(String[]args){ HashSet set=new HashSet(); set.add(white); //添加下面的6个无素,注意有重复值 set.add(red); set.add(blue); set.add(pink); set.add(orange); set.add(green); set.add(new String(blue)); System.out.println(容量:+set.size()); System.out.println(包含red吗?+set.contains(red)); Iterator it=set.iterator(); while(it.hasNext()) System.out.print(it.next()+ ); } } Map接口 Map用于保存具有映射关系的数据,因此Map中每个元素实质上是由键(Key)和值(Value)两个数据组成的,键和值是一对一的映射关系,Map就像数据库中的数据字典,键就像表中的主键,通过唯一的键就能找到相对应的值。 Map中的键是唯一的,不能重复的,值是可以重复的。 M
原创力文档

文档评论(0)