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  

Collections:
  1. Collections
  2. Get empty collection from Collections
  3. Do binary search
  4. Copy value to a List
  5. Get Enumeration from collection, create list from Enumeration
  6. Fill a list
  7. Get the max and min value from a Collection
  8. Fill n Copy object to a list
  9. Replace value in a list
  10. Reverse a list
  11. Get comparator in reverse order
  12. Rotate and shuffle a list
  13. Create singleton
  14. Sort a list
  15. Swap element in a list
  16. Get a synchronized collection
  17. Return an unmodifiable view of collections