Different Ways of Creating HashMaps

前端 未结 4 1420
盖世英雄少女心
盖世英雄少女心 2021-01-04 03:29

I\'ve been learning about HashMaps recently but I have one question that I can\'t seem to get a clear answer on. The main difference between -

HashMap hash1          


        
4条回答
  •  太阳男子
    2021-01-04 03:59

    Those are the options you have:

    J2SE <5.0 style:

     Map map = new HashMap();
    

    J2SE 5.0+ style (use of generics):

     Map map = new HashMap();
    

    Google Guava style (shorter and more flexible):

     Map map = Maps.newHashMap();
    

提交回复
热议问题