Java Collections singletonList() MethodLast Updated : 17 Mar 2025 The singletonList() method of Java Collections class is used to get an immutable list which contains only the specified object. SyntaxFollowing is the declaration of singletonList() method: Parameter
ReturnsThe singletonList() method returns an immutable List which contains only the specified object. ExceptionsNA Compatibility VersionJava 1.3 and above Example 1Output: Number List elements: [10] String List elements: [Hello India] Example 2Output: List value before: [One, Two, Three, One, Two, Three, TpointTech] List value after: [One] Example 3Output: 1. Enter the value: 55 Output: [55] 2. Enter the value: Java Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at myPackage.CollectionsSingletonListExample3.main(CollectionsSingletonListExample3.java:7) Next TopicJava Collections Class |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India