Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem: Cannot remove a key in HashMap

807569Aug 20 2006 — edited Aug 21 2006
import java.awt.*;
import java.util.*;
import java.util.concurrent.*;

public class Test
{
public static void main( String[] args )
{
ConcurrentHashMap<Point,Integer> hashMap = new ConcurrentHashMap<Point,Integer>();
hashMap.put( new Point( 1, 2 ), 1 );

System.out.println( hashMap.containsKey( new Point( 1, 2 ) ) );
hashMap.remove( new Point( 1, 2 ) );
System.out.println( hashMap.containsKey( new Point( 1, 2 ) ) );
}
}



The above code work fine, but it fails when I changed "Point" into "IntegerPoint" (a class wrote by me). What's the problems?


import java.awt.*;
import java.util.*;
import java.util.concurrent.*;

public class Test
{
public static void main( String[] args )
{
ConcurrentHashMap<IntegerPoint,Integer> hashMap = new ConcurrentHashMap<IntegerPoint,Integer>();
hashMap.put( new IntegerPoint( 1, 2 ), 1 );

System.out.println( hashMap.containsKey( new IntegerPoint( 1, 2 ) ) );
hashMap.remove( new IntegerPoint( 1, 2 ) );
System.out.println( hashMap.containsKey( new IntegerPoint( 1, 2 ) ) );
}
}



Thank you very much!!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2006
Added on Aug 20 2006
9 comments
190 views