Home » Java programming language

Java Collections emptySet() Method with Example

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

Collections Class emptySet() method

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

Syntax:

    public static final Set emptySet();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is Set, it returns an immutable set object which is empty.

Example:

// Java program is to demonstrate the example
// of Set emptySet() of Collections

import java.util.*;

public class EmptySet {
    public static void main(String args[]) {
        // By using emptySet() method is 
        // to get a empty set
        Set set = Collections.emptySet();

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

Output

set: []





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.