Google Collections 、guava 简单使用

沈皓君
2023-12-01


简化集合的创建
List<Person> personList= Lists.newLinkedList();
Set<Person> personSet= Sets.newHashSet();
Map<String,Person> personMap= Maps.newHashMap();
Integer[] intArrays= ObjectArrays.newArray(Integer.class,10);


简化集合的初始化

Set<String> set = Sets.newHashSet("one","two","three");

List<String> list = Lists.newArrayList("one","two","three");

Map<String, String> map = ImmutableMap.of("ON","TRUE","OFF","FALSE");

 
List<Person> personList2= Lists.newArrayList(new Person(1,  "Ryu"), new Person(2, "Ken"));

Set<Person> personSet2= Sets.newHashSet(new Person(1, "Ryu"), new Person(2, "Ken"));

Map<String,Person> personMap2= ImmutableMap.of("p1", new Person(1, "Ryu"), "p2", new Person(2, "Ken"));



最新maven坐标(Dec 09, 2015) :

<dependency>
 <groupId>com.google.guava</groupId>
 <artifactId>guava</artifactId>
 <version>19.0</version>
</dependency>


 类似资料: