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.


/*from w w w.j a  v a2 s  .c o m*/

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.