Java 33 - list map set

PHOTO EMBED

Sun Nov 26 2023 17:18:19 GMT+0000 (Coordinated Universal Time)

Saved by @Java

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);

 } 

}
content_copyCOPY