HashSet的使用
/**
* HashSet内的元素是唯一的(是无序的)
* 存入顺序和取出顺序是不一致的
* 不会对元素进行排序
*/
//创建对像
HashSet<String> hashSet=new HashSet<String>();
hashSet.add("qwe");
hashSet.add("qwe");
hashSet.add("ab");
hashSet.add("aa");
hashSet.add("c");
//返回大小
int size = hashSet.size();
//是否为空
boolean empty = hashSet.isEmpty();
//如果存在,则从该集合中删除指定的元素。
boolean remove = hashSet.remove("b");//删除了为true
//是否包含元素
boolean contains = hashSet.contains("aa");
//遍历元素
Iterator<String> iterator = hashSet.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
System.out.println(next);
}
//返回数组
Object[] array = hashSet.toArray();
String[] strArr=(String[])array;//强制转换
HashMap的使用
/**
* 存入元素和取出元素的顺序是一致的
* 键是唯一的
* HashMap
* 不会对元素进行排序
*/
//创建对象
HashMap<String, Integer> hashMap=new HashMap<String, Integer>();
//添加元素
hashMap.put("cc", 234);
hashMap.put("qwe",