Generic Set in Java
by , 02-18-2012 at 03:45 PM (487 Views)
It is also possible to generify the java.util.Set. Set instances in these cases might of a specific type.
Instances of that type in such cases could be inserted or read, from that set.
Usage of generic Set is explained here.
Adding Elements to a Generic SetJava Code: This is the code to explain usage of generic SetSet<String> set = new HashSet<String>;
To a set, specific String type is added by using this code.
Iterating a Generic SetJava Code: This is the code to add specific String type in a SetSet<String> set = new HashSet<String>; String string1 = "a string"; set.add(string1);
To iterate over generic Set, use this code:
Java Code: This is the code to iterate over generic SetSet<String> set = new HashSet<String>; Iterator<String> iterator = set.iterator(); while(iterator.hasNext()){ String aString = iterator.next(); }









Email Blog Entry
Size Reduced for Images in PDF &...
05-15-2013, 05:53 PM in Java Software