How to Create Empty List Using Collections Class in Java


Here this tutorial would help us to create an empty list with Collections class.

Source Code

package com.beginner.examples;

import java.util.Collections;
import java.util.List;
 
public class EmptyListExample {
 
    public static void main(String a[]){
        
    	// use emptyList()
        List list = Collections.emptyList();
        System.out.println("List: " + list);
    }
}

Output:

List: []

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments