Home » Java programming language

Java Collections emptyList() Method with Example

Collections Class emptyList() method: Here, we are going to learn about the emptyList() method of Collections Class with its syntax and example.
Submitted by Preeti Jain, on February 03, 2020

Collections Class emptyList() method

  • emptyList() method is available in java.util package.
  • emptyList() method is used to returns the immutable empty list.
  • emptyList() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • emptyList() method does not throw an exception at the time of returning an empty list.

Syntax:

    public static final List emptyList();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is List, it returns an immutable blank list.

Example:

// Java program is to demonstrate the example
// of List emptyList() of Collections

import java.util.*;

public class EmptyList {
    public static void main(String args[]) {
        // By using emptyList() method is 
        // to get a empty list
        List < Integer > list = Collections.emptyList();

        // Display Empty List
        System.out.println("list: " + list);
    }
}

Output

list: []



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.