VOOZH about

URL: https://www.geeksforgeeks.org/java/java-collections-emptylist-method-with-examples/

⇱ Java Collections emptyList() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Collections emptyList() Method with Examples

Last Updated : 13 Jan, 2022

The emptyList() method of Java Collections returns the list with no elements. This method is immutable. That is, we can not do any modifications after creating this method.

Syntax:

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

Parameters: It will not accept any parameters

Return: This method will return an empty list

Example 1: 


Output
[]

Example 2:

Output:

Exception in thread "main" java.lang.UnsupportedOperationException
 at java.util.AbstractList.add(AbstractList.java:148)
 at java.util.AbstractList.add(AbstractList.java:108)
 at GFG.main(GFG.java:11)
Comment