Advertisement
JeffGrigg

Test17_HM_B

Aug 12th, 2018
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.04 KB | None | 0 0
  1. import java.util.HashMap;
  2.  
  3. public class Test17_HM_B {
  4.     public static void main(String[] args) {
  5.         final HashMap<Object,Object> hashMapOne = new HashMap<>();
  6.  
  7.         hashMapOne.put(1, hashMapOne);
  8.  
  9.         System.out.println("Size    :"+hashMapOne.size());
  10.         System.out.println("Elements : "+hashMapOne.toString());
  11.         System.out.println();
  12.  
  13.         final HashMap<Object,Object> hashMapTwo = new HashMap<>();
  14.  
  15.         hashMapTwo.put(2, hashMapTwo);
  16.  
  17.         System.out.println("Size    :"+hashMapTwo.size());
  18.         System.out.println("Elements : "+hashMapTwo.toString());
  19.         System.out.println();
  20.  
  21.         hashMapTwo.put(1, hashMapOne);
  22.         hashMapOne.put(2, hashMapTwo);
  23.  
  24.         System.out.println("Size    :"+hashMapOne.size());
  25.         System.out.println("Elements : "+hashMapOne.toString());    // It "blows up" here.
  26.         System.out.println();
  27.         System.out.println("Size    :"+hashMapTwo.size());
  28.         System.out.println("Elements : "+hashMapTwo.toString());
  29.         System.out.println();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement