Get empty collection from Collections

TypeFieldSummary
static ListEMPTY_LISTThe empty list (immutable).
static MapEMPTY_MAPThe empty map (immutable).
static SetEMPTY_SETThe 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();
  }
}
  
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.