Map集合
Map集合的特点
- Map集合的最大特点就是具有映射关系,Map<Key,Value>;Map集合里存取Key值与Value值,Map集合中的Key是存储在一个Set集合里,所有Key值是不允许重复的,我们可以通过Key值取到对应的Value
- Value中,可以是一个集合,也可以是别的类型的值,所以说Map集合中可以嵌套集合
Map<Key,Value>object=new HashMap<>();
Map集合中的方法
- 由于Map集合中Key是通过一个Set集合存储的,所以可以通过KeySet方法得到Map集合中的Key
public static void main(String[] args) {
Map<Integer, Integer> map=new HashMap<Integer, Integer>();
map.put(1, 2);
map.put(2, 2);
map.keySet();//得到所有的Key值
}
- 由于Map集合具有映射关系,可以通过Key取到相应的Value值
public static void main(String[] args) {
Map<Integer, Integer> map=new HashMap<Integer, Integer>();
map.put(1, 2);
map.put(2, 2);
System.out.println(map.get(key));//通过确定的Key值,取到相应的Value值
}
TreeMap
TreeMap集合与TreeSet集合类似,可以进行排序,也可以通过重写compareTo方法,也可以调用一些列的方法
然后集合这一方面就先到这里