Advertisement
S0lll0s

Nested HashMap s

Apr 22nd, 2013
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.awt.image.BufferedImage;
  2. import java.util.HashMap;
  3.  
  4.  
  5. public class Test {
  6.     public static void main( String[] args ) {
  7.         HashMap<Boolean,BufferedImage> one;// = new HashMap<Integer,BufferedImage>();
  8.         HashMap<Boolean,BufferedImage> two;// = new HashMap<Integer,BufferedImage>();
  9.         HashMap<Integer, HashMap<Boolean,BufferedImage>> hand; // = new HashMap<Integer, HashMap<Boolean,BufferedImage>>();
  10.        
  11.         one = new HashMap<Boolean, BufferedImage>();
  12.         two = new HashMap<Boolean, BufferedImage>();
  13.        
  14.         one.put( true, new BufferedImage(0, 0, 0) );
  15.         one.put( false, new BufferedImage(255, 0, 0) );
  16.        
  17.         two.put( true, new BufferedImage(0, 255, 0) );
  18.        
  19.         hand = new HashMap<Integer, HashMap<Boolean,BufferedImage>>();
  20.         hand.put( 1, one );
  21.         hand.put( 2, two );
  22.        
  23.         System.out.println( hand.get( 1 ) ); //should basically be "one"
  24.         System.out.println( ((HashMap<Boolean,BufferedImage>) hand.get( 1 ) ).get(true) ); //should be two's buffImg
  25.         System.out.println( ((HashMap<Boolean,BufferedImage>) hand.get( 1 ) ).get(false) ); //should error
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement