The java.util.Collections.singleton() method is used to create an immutable set containing a single specified element. This method ensures that only one object of the specified type is created.
Code Example:
// create a singleton set
Set singletonSet = Collections.singleton("example");
// print the set
System.out.println(singletonSet);
Output:
[example]
This method can be found in the java.util.Collections package library.
Java Collections.singleton - 30 examples found. These are the top rated real world Java examples of java.util.Collections.singleton extracted from open source projects. You can rate examples to help us improve the quality of examples.