Empty Collections
In this chapter you will learn:
Get empty collection from Collections
static List EMPTY_LIST
The empty list (immutable).static Map EMPTY_MAP
The empty map (immutable).static Set EMPTY_SET
The empty set (immutable).static<T> List<T> emptyList()
Returns the empty list (immutable).static<K,V> Map<K,V> emptyMap()
Returns the empty map (immutable).static<T> Set<T> emptySet()
Returns the empty set (immutable).
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
//j a va 2 s . c om
public class Main {
public static void main(String args[]) {
List list = Collections.EMPTY_LIST;
Set set = Collections.EMPTY_SET;
Map map = Collections.EMPTY_MAP;
List<String> s = Collections.emptyList();
Set<Long> l = Collections.emptySet();
Map<Date, String> d = Collections.emptyMap();
}
}
Next chapter...
What you will learn in the next chapter:
- How to use Java Comparator to create customized comparison method
- TreeSet and Comparator
- Get comparator in reverse order
- Use reversed Comparator to sort a list