Java Collections newSetFromMap() MethodThe newSetFromMap() method of Java Collections class is used to return a set backed by the specified map. The resulting set displays the same ordering, concurrency, and performance characteristics as the backing map. SyntaxFollowing is the declaration of newSetFromMap() method: Parameter
ReturnsThe newSetFromMap() method returns the set backed by the specified map. ExceptionsIllegalArgumentException- It throws this exception if map is not empty. Compatibility VersionJava 1.6 and above Example 1Test it NowOutput: Set is: [Karan, Raj, Rahul] Map is: {Karan=true, Raj=true, Rahul=true} Example 2Test it NowOutput: Set is: [1] Map is: {1=true} Example 3Test it NowOutput: Users: [] Users: [Java, PHP] Next TopicJava Collections Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India