Maps.newHashMap() 和 Lists.newArrayList()

简介: Maps.newHashMap() 和 Lists.newArrayList()

区别:与new HashMap()  与 new  ArrayList()  没啥区别,主要目的是为了简化,不需要你手动写泛型

1:添加依赖:

       <!-- google java lib -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>17.0</version>
    </dependency>

2:实现方式

  HashMap<Object, Object> map = Maps.newHashMap();
  List<Object> list = Lists.newArrayList();

3:Maps.newHashMap() 部分源码

public static <K, V> HashMap<K, V> newHashMap() {
        return new HashMap();
    }

4: Lists.newArrayList() 部分源码

 public static <E> ArrayList<E> newArrayList() {
        return new ArrayList();
    }
目录
相关文章
Guava - Maps.difference
Guava - Maps.difference
576 0
LeetCode 160. Intersection of Two Linked Lists
编写一个程序,找到两个单链表相交的起始节点。
64 0
LeetCode 160. Intersection of Two Linked Lists
|
API
Google Guava之Maps&Lists&Sets
日常开发中,使用最多的就是集合了,所以避免不了对集合的各种操作,本篇文章来看一下,Guava中都有哪些常用的集合操作的API可以简化我们的代码。
220 0
Google Guava之Maps&Lists&Sets
|
NoSQL MongoDB 数据库
DeprecationWarning: count is deprecated. Use Collection.count_documents instead
当我使用pymongo查询出对应的cursor(find出的document的迭代器),然后查看查询出数据的数量时使用如下代码: ```python db = MongoClient(host='192.168.1.3', port=27017) # dbname为操作的数据库名称,collectionname为操作的集合名称
336 0
Data Structures and Algorithms (English) - 6-4 Reverse Linked List(20 分)
Data Structures and Algorithms (English) - 6-4 Reverse Linked List(20 分)
116 0
Why Opportunity list is empty
Created by Jerry Wang on Nov 27, 2014 UI上发现Opportunity list为空:
Why Opportunity list is empty
|
固态存储 SDN
1028 List Sorting (25)
#include #include #include #include #include using namespace std; int c; struct node{ string id, name;...
859 0
|
数据建模
1052. Linked List Sorting (25) 22'
#include #include #include using namespace std; /* 题目大意:对结构体进行排序 分析:建立结构体数组,按照从首地址开始的顺序(直到-1)遍历一遍整个链表, */ ...
983 0
|
数据建模
1133. Splitting A Linked List (25)
Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear ...
1412 0