Advertisement
Guest User

Untitled

a guest
Nov 18th, 2009
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.*;
  2. public class CollisionTest {
  3.     public static void main ( String [] args ) {
  4.         String s = new String("ese");
  5.         System.out.println( s.hashCode() );
  6.         String ese = new String("ese");
  7.         System.out.println( ese.hashCode() );
  8.         // same hash right?
  9.         Map map = new HashMap();
  10.         map.put( s, 1 );
  11.         map.put( ese, 2 );
  12.         SomeClass some = new SomeClass();
  13.         System.out.println( some.hashCode() );
  14.         // still  same hash right?
  15.         map.put( some , 3 );
  16.         // what would we get?
  17.         System.out.println( map.get( s ) );
  18.         System.out.println( map.get( ese ) );
  19.         System.out.println( map.get( some ) );
  20.     }
  21. }
  22. class SomeClass {
  23.     public int hashCode() {
  24.         return 100727;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement