How to instantiate a collection in Java using Generics?

How to instantiate a collection in Java using Generics?



Set<String> myStringSet = new HashSet();

Set<String> myStringSet = new HashSet<String>();

Set<String> myStringSet = new HashSet<String>();

Set<String> myStringSet = new HashSet<String>();

Type safety: The expression of type HashSet needs unchecked conversion
to conform to Set <String>.


Learn More :