fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String a1 = "blablabla";
  13. String b1 = a1;
  14.  
  15. System.out.println(b1);
  16. System.out.println(a1);
  17.  
  18. System.out.println(b1.hashCode());
  19. System.out.println(a1.hashCode());
  20.  
  21. a1 = "wow";
  22.  
  23. System.out.println(b1.hashCode());
  24. System.out.println(a1.hashCode());
  25.  
  26. System.out.println(b1);
  27. System.out.println(a1);
  28.  
  29. Set<String> a = new HashSet<String>();
  30.  
  31. Set<String> b = a;
  32.  
  33. a.add("hey");
  34. a.add("HellO");
  35.  
  36. System.out.println(b.size());
  37. System.out.println(b.hashCode()); // This is important
  38. System.out.println(a.hashCode()); // This is important too!!!
  39.  
  40. a.clear();
  41.  
  42. System.out.println(a.size()); // same hashcode i.e. gets affected by the change.
  43. System.out.println(b.size());
  44. }
  45. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
blablabla
blablabla
1304972471
1304972471
1304972471
117919
blablabla
wow
2
69712814
69712814
0
0