package com.ram;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
/**
*
* @author ramakrishna.v
*
*/
public class SetInterfactExamples {
public static void main(String args[]) {
Set<String> hashSet = new HashSet<String>();
hashSet.add("a");
hashSet.add("b");
hashSet.add("c");
retrieveValues("Set","HashSet",hashSet);
Set<String> treeSet1 = new TreeSet<String>();
treeSet1.add("R");
treeSet1.add("A");
treeSet1.add("M");
retrieveValues("Set","TreeSet",treeSet1);
SortedSet<String> treeSet2 = new TreeSet<String>();
treeSet2.add("R");
treeSet2.add("A");
treeSet2.add("M");
retrieveValues("SortedSet","TreeSet",treeSet2);
Set<String> linkedHashset = new LinkedHashSet<String>();
linkedHashset.add("R");
linkedHashset.add("A");
linkedHashset.add("M");
retrieveValues("Set","LinkedHashSet",linkedHashset);
}
@SuppressWarnings({ "rawtypes"})
static void retrieveValues(String var1,String var2,Collection collection) {
System.out.println(var1+" interface using "+var2+" class");
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
String string = (String) iterator.next();
System.out.println(string);
}
System.out.println("===========================");
}
}
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
/**
*
* @author ramakrishna.v
*
*/
public class SetInterfactExamples {
public static void main(String args[]) {
Set<String> hashSet = new HashSet<String>();
hashSet.add("a");
hashSet.add("b");
hashSet.add("c");
retrieveValues("Set","HashSet",hashSet);
Set<String> treeSet1 = new TreeSet<String>();
treeSet1.add("R");
treeSet1.add("A");
treeSet1.add("M");
retrieveValues("Set","TreeSet",treeSet1);
SortedSet<String> treeSet2 = new TreeSet<String>();
treeSet2.add("R");
treeSet2.add("A");
treeSet2.add("M");
retrieveValues("SortedSet","TreeSet",treeSet2);
Set<String> linkedHashset = new LinkedHashSet<String>();
linkedHashset.add("R");
linkedHashset.add("A");
linkedHashset.add("M");
retrieveValues("Set","LinkedHashSet",linkedHashset);
}
@SuppressWarnings({ "rawtypes"})
static void retrieveValues(String var1,String var2,Collection collection) {
System.out.println(var1+" interface using "+var2+" class");
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
String string = (String) iterator.next();
System.out.println(string);
}
System.out.println("===========================");
}
}
No comments:
Post a Comment