Java Collection Tutorial - Java Collections.emptyList()








Syntax

Collections.emptyList() has the following syntax.

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

Example

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
      emptylst.add("from java2s.com");
   }    
}

The code above generates the following result.