
import java.util.*;
public class CollectFrame { public static void main(String [] args) { System.out.println( "Collection Example!\n" ); //int size; HashSet collection = new HashSet(); String str1 = "Y", str2 = "W", str3 = "G", str4 = "B"; //Iterator iterator;
collection.add(str1); collection.add(str2); collection.add(str3); collection.add(str4); System.out.println("Collection data: "+str1," "+str2," "+str3," "+str4); thanks

Here is an example of HashSet example.
import java.util.*;
public class CollectFrame {
public static void main(String [] args) {
System.out.println( "Collection Example!\n" );
//int size;
HashSet collection = new HashSet();
String str1 = "Y",str2 = "W", str3 = "G", str4 = "B";
//Iterator iterator;
collection.add(str1);
collection.add(str2);
collection.add(str3);
collection.add(str4);
Iterator itr = collection.iterator();
System.out.println("HashSet contains : ");
while(itr.hasNext())
System.out.println(itr.next());
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.