http://www.java265.com/JavaCourse/202206/3735.html
Google guava簡介:
1、Guava 是一組來自 Google 的核心 Java 庫,包括新的集合型別(如 multimap 和 multiset)、不可變集合、圖形庫以及用于并發、I/O、散列、快取、原語、字串等的實用程式!被廣泛應用于 Google 的大多數 Java 專案中,也被許多其他公司廣泛使用,
2、guava github 開源地址:GitHub - google/guava: Google core libraries for Java
3、官網用戶手冊:https://github.com/google/guava/wiki
4、引入com.google.guava 依賴的方法:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
下文筆者講述一個新型的Map結構,如下所示
google guava提供一中可以存在重復鍵的map結構 當我們向一個map中設定多個鍵相同的值時,不會被替換 而會疊加, 后續作為一個陣列回傳
例: 在原生的代碼中,一個map需存盤list需采用以下方式
Map<String,List<Integer>> map = new HashMap<String,List<Integer>>();
List<Integer> list = new ArrayList<Integer>();
list.add(88888);
list.add(9999);
map.put("keyTest", list);
System.out.println(map.get("keyTest"));
使用Google guava寫法,將使map生成List更簡單
Multimap<String,Integer> mapM = ArrayListMultimap.create();
mapM.put("keyTest",1);
mapM.put("keyTest",2);
System.out.println(mapM.get("keyTest"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/492932.html
標籤:Java
上一篇:Java集合類詳解
