7 Replies Latest reply: Aug 31, 2010 1:52 PM by 807580 RSS

    (Shock!) TreeMap, HashMap, containsKey are difference !?

    807580
        TreeMap<TestK, TestV> treeMapTest = new TreeMap();
        treeMapTest.put( new TestK( "nine" ), new TestV( 9 ) );
          if ( treeMapTest.containsKey( new TestK( "nine" ) ) )
            System.out.println( "Redefine: " + "nine" );  // into, duplicate !
      
        HashMap<TestK, TestV> hashMapTest = new HashMap();
        hashMapTest.put( new TestK( "nine" ), new TestV( 9 ) );
          if ( hashMapTest.containsKey( new TestK( "nine" ) ) )
            System.out.println( "Redefine: " + "nine" );  // not into !?  not duplicate !?
      p.s.
      class TestK implements Comparable<TestK> // <editor-fold defaultstate="collapsed" desc="{...}">
      {
      
        String mName;
      
        TestK( String name ) {
          mName = new String( name );
        } // Test()
      
        public int compareTo( TestK o ) {
          return mName.compareTo( o.mName );
          // throw new UnsupportedOperationException( "Not supported yet." );
        }
      } // class Test // </editor-fold>
      
      
      class TestV // <editor-fold defaultstate="collapsed" desc="{...}">
      {
      
        int mValue;
      
        TestV( int value ) {
          mValue = value;
        } // TestV()
      } // class TestV // </editor-fold>
      Tell me why ?