CBredlow

Driver tests for various hash maps, ordered and unordered ma

Oct 27th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public class Driver {
  2.    // Complete a driver to test the methods of the Maps
  3.     public static void main(String [] args)
  4.     {
  5.        
  6.        HashMap<Integer, String> newMap = new HashMap();
  7.         newMap.put( 0,"Alfalfa");
  8.         newMap.put(1, "Bologna");
  9.         newMap.put(2, "Canuck");
  10.         newMap.put(13,"Jabberwocky");
  11.         newMap.put(3, "Digress");
  12.         newMap.put(4, "Egress");
  13.         newMap.put(5, "Ferdinand");
  14.         /*for(int i = 0; i < newMap.size(); i++)
  15.         {
  16.             System.out.println(newMap.get(i));
  17.         }*/
  18.         for(String s: newMap.values())
  19.         {
  20.             System.out.println(s);
  21.         }
  22.        HashMap<Integer, String> newMap2 = new HashMap();
  23.         newMap2.put(0, "Bill");
  24.         newMap2.put(5, "Rawr");
  25.         newMap2.put(6, "Aardvark");
  26.         newMap.putAll(newMap2);
  27.         for(int i = 0; i <newMap2.size(); i++)
  28.         {
  29.             System.out.println(newMap2.get(i));
  30.         }
  31.         System.out.println(newMap2.remove(2));
  32.         newMap.clear();
  33.         //System.out.println(newMap.get(0));
  34.         System.out.println(newMap2.containsValue("Bobby"));
  35.         for(String s: newMap2.values())
  36.         {
  37.             System.out.println(s);
  38.         }
  39.        
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment