package org.JavaIncloud.java;

import java.util.HashSet;
import java.util.Set;

public class SetShowCase
{
	public static void main(String...JavaInCloud) 
	{
		/*create an ArrayList(a class implements List) and assign 
		 * to List as we can not create object for List interface*/
		Set<String>	animals = new HashSet<String>();
		
		//Store some animal name to the collection of animal object(Here String)
		animals.add("Tiger");animals.add("Monkey");
		animals.add("Cow");animals.add("Cat");
		animals.add("Dog");
		
		/*print the Set, it'll print the animal name, as internally ArrayList  overwrite toString()*/
		System.out.println("Animal Name>>"+animals);
		//output:Animal Name>>[Cat, Dog, Tiger, Monkey, Cow]
		
		/*there is not get() method for Set hence it'll not work, instead it'll give you a compilation error*/
		//System.out.println(Animal.get(3));
		
		/*Retrieve the element from set. 
		 * This is how for-each loop works if you want then you can use Iterator also
		 * Get the iterator from HashSet and iterate it. Iterator<String> iterator = animals.iterator();*/
		for (String animal : animals) 
		{
			System.out.print(animal+",");
		}
		//output: Cat,Tiger,Dog,Monkey,Cow,
		
		/*If you are bothering about order of the set then you have go for LinedHashSet and TreeSet.
		* HashSet makes no guarantees as to the iteration order of the set; in particular, 
		* it does not guarantee that the order will remain constant over time. This class permits the null element.*/	
	}
}
