import java.util.*; public class LabTask33 { public static void main(String args[]) { //create a HashSet to store Strings HashSet<String> hs=new HashSet<String>(); //Store some String elements hs.add("India"); hs.add("America"); hs.add("Japan"); hs.add("China"); hs.add("America"); //view the HashSet System.out.println ("HashSet = " + hs); //add an Iterator to hs Iterator it = hs.iterator (); //display element by element using Iterator System.out.println("Elements Using Iterator: "); while(it.hasNext()) { String s=(String)it.next(); System.out.println(s); } //create an empty stack to contain Integer objects Stack<Integer>st=new Stack<Integer>(); st.push(new Integer(10)); st.push(new Integer(20)); st.push(new Integer(30)); st.push(new Integer(40)); st.push (new Integer(50)); System.out.println(st); System.out.println("Element at top of the stack is: "+st.peek()); System.out.println("Removing element at the TOP of the stack: "+st.pop()); System.out.println("The new stack is: "+st); HashMap<Integer,String> hm=new HashMap<Integer,String>(); hm.put(new Integer(101),"Naresh"); hm.put(new Integer(102),"Rajesh"); hm.put(new Integer(103),"Suresh"); hm.put(new Integer(104),"Mahesh"); hm.put(new Integer(105),"Ramesh"); Set<Integer> set=new HashSet<Integer>(); set=hm.keySet(); System.out.println(set); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter