Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CollisionTest {
- public static void main ( String [] args ) {
- String s = new String("ese");
- System.out.println( s.hashCode() );
- String ese = new String("ese");
- System.out.println( ese.hashCode() );
- // same hash right?
- Map map = new HashMap();
- map.put( s, 1 );
- map.put( ese, 2 );
- SomeClass some = new SomeClass();
- System.out.println( some.hashCode() );
- // still same hash right?
- map.put( some , 3 );
- // what would we get?
- System.out.println( map.get( s ) );
- System.out.println( map.get( ese ) );
- System.out.println( map.get( some ) );
- }
- }
- class SomeClass {
- public int hashCode() {
- return 100727;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement