Java Collection Tutorial - Java Collections.emptyList()


Collections.emptyList() has the following syntax.

public static final <T> List <T> emptyList()


In the following code shows how to use Collections.emptyList() method.

/*  w w  w . ja v a 2s .  c  om*/

import java.util.Collections;
import java.util.List;

public class Main {
   public static void main(String args[]) {
      // create an empty list    
      List<String>  emptylst = Collections.emptyList();
      System.out.println("Created empty immutable list: "+emptylst);
      // try to add elements

The code above generates the following result.