java.lang.IllegalArgumentException: Map is non-empty

Asked on May 26, 2013
Hi All,
I am trying to run Collections.newSetFromMap but got below error, any clue from java folks.
I am trying to run Collections.newSetFromMap but got below error, any clue from java folks.
Exception in thread "main" java.lang.IllegalArgumentException: Map is non-empty
at java.util.Collections$SetFromMap.<init>(Unknown Source)
at java.util.Collections.newSetFromMap(Unknown Source)

Replied on May 26, 2013
you have to declare argument in Collections.newSetFromMap like this
Collections.newSetFromMap(new HashMap<Object,Boolean>())
You need to keep Collections.newSetFromMap argument as empty.

Replied on May 26, 2013
Collections.newSetFromMap should not be used for TreeMap or HashMap as they already implement set, it should be used for WeakHashMap etc