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;
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();
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Letters {
private List<String> letterList;
Letters() {
letterList = Collections.emptyList();
}
Letters(String... letterName) {
letterList = new ArrayList<String>();
for (String name : letterName)
letterList.add(name);
}
@Override
public String toString() {
return letterList.toString();
}
}
public class Main{
public static void main(String[] args) {
Letters letters = new Letters();
System.out.println(letters);
letters = new Letters("S", "R", "B", "O");
System.out.println(letters);
}
}
Home
Java Book
Collection
Java Book
Collection
Collections:
- Collections
- Get empty collection from Collections
- Do binary search
- Copy value to a List
- Get Enumeration from collection, create list from Enumeration
- Fill a list
- Get the max and min value from a Collection
- Fill n Copy object to a list
- Replace value in a list
- Reverse a list
- Get comparator in reverse order
- Rotate and shuffle a list
- Create singleton
- Sort a list
- Swap element in a list
- Get a synchronized collection
- Return an unmodifiable view of collections