本文介紹了創建 HashMap 的不同方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我最近一直在學習 HashMaps,但我有一個問題似乎無法得到明確的答案.主要區別 -
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 = new HashMap();
對比
HashMap<,>hash1 = new HashMap <,> (); //Filled in with whatever Key and Value you want.
我認為當您定義 HashMap 時,它需要鍵和值.任何幫助將非常感激.謝謝.
I thought when you define a HashMap it requires the Key and Value. Any help would be much appreciated. Thank You.
推薦答案
這些是你的選擇:
J2SE <5.0 風格:
J2SE <5.0 style:
Map map = new HashMap();
J2SE 5.0+ 風格(使用泛型):
J2SE 5.0+ style (use of generics):
Map<KeyType, ValueType> map = new HashMap<KeyType, ValueType>();
Google Guava 樣式(更短更靈活):
Google Guava style (shorter and more flexible):
Map<KeyType, ValueType> map = Maps.newHashMap();
這篇關于創建 HashMap 的不同方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!