import java.util.*;
public class ClearMethod {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<Integer, String> map1 = new HashMap<>();
map1.put(1, "One");
map1.put(2, "Two");
map1.put(3, "Three");
map1.put(4, "Four");
map1.put(5, "Five");
map1.put(6, "Six");
map1.put(7, "Seven");
map1.put(8, "Eight");
Set set = map1.entrySet();
Iterator itr = set.iterator();
while(itr.hasNext())
{
Map.Entry<Integer, String> me = (Map.Entry)itr.next();
System.out.print("Key : "+me.getKey());
System.out.println(", Value : "+me.getValue());
}
System.out.println("\n After clear() method, List : ");
map1.clear();
Set set1 = map1.entrySet();
Iterator itr1 = set1.iterator();
while(itr1.hasNext())
{
Map.Entry<Integer, String> me1 = (Map.Entry)itr1.next();
System.out.print("Key : "+me1.getKey());
System.out.println(", Value : "+me1.getValue());
}
}
}
No comments:
Post a Comment