public class CollectionFactory extends Object
// simple
List<Integer> list1 = CollectionFactory.list();
// nested
List<List<String>> list2 = CollectionFactory.list();
// a multi-map
Map<String, List<Integer>> multiMap = CollectionFactory.map();
| Constructor and Description |
|---|
CollectionFactory() |
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
list()
Returns a new
List object. |
static <K,V> Map<K,V> |
map()
Returns a new
Map object. |
static <K,V> Map<K,V> |
orderedMap()
Returns a new
Map object that maintains insertion
order. |
static <T> Set<T> |
orderedSet()
Returns a new
Set instance that maintains
the insertion order of its elements. |
static <T> Set<T> |
set()
Returns a new
Set instance. |
static <K,V> SortedMap<K,V> |
sortedMap()
Returns a new
SortedMap object. |
static <T> SortedSet<T> |
sortedSet()
Returns a new
SortedSet instance. |
static <T> Stack<T> |
stack()
Returns a new
Stack object. |
public static <K,V> Map<K,V> map()
Map object. The returned
object is a HashMap.
Example of use:
Map<Foo, Bar> myMap = CollectionFactory.map();
K - key typeV - value typepublic static <K,V> Map<K,V> orderedMap()
Map object that maintains insertion
order. The returned object is a LinkedHashMap.
Example of use:
Map<Foo, Bar> myMap = CollectionFactory.orderedMap();
K - key typeV - value typepublic static <K,V> SortedMap<K,V> sortedMap()
SortedMap object. Key type K must
implement Comparable. The returned object is a
TreeMap.
Example of use:
Map<Foo, Bar> myMap = CollectionFactory.sortedMap();
K - key typeV - value typepublic static <T> List<T> list()
List object. The returned object is
an ArrayList.
Example of use:
List<Foo> myList = CollectionFactory.list();
T - element typepublic static <T> Stack<T> stack()
Stack object.
Example of use:
Stack<Foo> myStack = CollectionFactory.stack();
T - element typepublic static <T> Set<T> set()
Set instance. The returned object is
a HashSet.
Example of use:
Set<Foo> mySet = CollectionFactory.set();
T - element typepublic static <T> Set<T> orderedSet()
Set instance that maintains
the insertion order of its elements.
Example of use:
Set<Foo> mySet = CollectionFactory.set();
T - element typepublic static <T> SortedSet<T> sortedSet()
SortedSet instance. The type T
must implement Comparable. The returned object
is a TreeSet.
Example of use:
Set<MyObject> foo = CollectionFactory.sortedSet();
T - element typeCopyright © 2009–2018. All rights reserved.