1、实现Map接口的类用来存储 键值对
2、Map接口实现的类有HashMap和TreeMap等;
3、Map类中存储的键值对通过键值来标示,因此键值不能重复(equals() );
Tips:
1、如果某个类重写equals方法,那么必须重写hashCode方法;
2、auto-boxing/unboxing --- 在合适的时机进行打包、解包
自动将基础类型转变为对象;
自动将对象转换为基础类型;
Map m1 = new HashMap();
Map m2 = new HashMap();
m1.put( "one", new Integer( "1" ) );//m1.put( "one", 1);
m1.put( "two", new Integer( "2" ) );//m1.put( "two", 2);
m1.put( "three", new Integer( "3" ) );//m1.put( "threee", 3);
m2.put( "A", new Integer( "1" ) );//m1.put( "A", 1);
m2.put( "B", new Integer( "2" ) );//m1.put( "B", 2);
阅读(579) | 评论(0) | 转发(0) |