HashMap map= new HashMap(); Hashmap map=null;有什么区别?还有购物车,怎么添加商品对象的呢?```````````````````````````````

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 19:48:01
HashMap map= new HashMap(); Hashmap map=null;有什么区别?还有购物车,怎么添加商品对象的呢?```````````````````````````````

HashMap map= new HashMap(); Hashmap map=null;有什么区别?还有购物车,怎么添加商品对象的呢?```````````````````````````````
HashMap map= new HashMap(); Hashmap map=null;有什么区别?
还有购物车,怎么添加商品对象的呢?
```````````````````````````````

HashMap map= new HashMap(); Hashmap map=null;有什么区别?还有购物车,怎么添加商品对象的呢?```````````````````````````````
HashMap map=new HashMap();
实例化一个HashMap对象,这是你可以对map进行任何操作,如put()等
HashMap map=null;
你声明一个HashMap变量,他没有指向任何对象,现在map是指向null的句柄对他操作会发生空指针异常,你需要为其赋值后在使用,可以用一个返回值为HashMap的方法或一个已经实例化的Map对象为其赋值.
购物车的问题你需要再详细说明一下