title: TreeMap putting BigDecimal key with trailing zero after decimal has no effect
body: <p>Putting value in key in Map not adding value in key</p>
  <pre><code>public static void putKey() {
      TreeMap&lt;BigDecimal,String&gt; trmap = new TreeMap&lt;BigDecimal,String&gt;();
      MathContext mc = new MathContext(2);
      BigDecimal b1 = new BigDecimal(3.1,mc);
      BigDecimal b2 = new BigDecimal(3.10,mc);
      BigDecimal b3 = new BigDecimal(3.2,mc);
      BigDecimal b4 = new BigDecimal(3.3,mc);
      BigDecimal b5 = new BigDecimal(3.4,mc);
      
      trmap.put(b1, &quot;3.1&quot;);
      trmap.put(b2, &quot;3.10&quot;);
      trmap.put(b3, &quot;3.2&quot;);
      trmap.put(b4, &quot;3.3&quot;);
      trmap.put(b5, &quot;3.4&quot;);
      
      System.out.println(trmap);
  }
  </code></pre>
  <p>in the above map 3.10 is not added in the key.</p>
  <p>so I have tried to compute the hash code for both values</p>
  <pre><code>public static void putKey() {
      TreeMap&lt;BigDecimal, String&gt; trmap = new TreeMap&lt;BigDecimal, String&gt;();
      MathContext mc = new MathContext(2);
      BigDecimal b1 = new BigDecimal(3.1, mc);
      BigDecimal b2 = new BigDecimal(3.10, mc);
      BigDecimal b3 = new BigDecimal(3.2, mc);
      BigDecimal b4 = new BigDecimal(3.3, mc);
      BigDecimal b5 = new BigDecimal(3.4, mc);
  
      trmap.put(b1, &quot;3.1&quot;);
      trmap.put(b2, &quot;3.10&quot;);
      trmap.put(b3, &quot;3.2&quot;);
      trmap.put(b4, &quot;3.3&quot;);
      trmap.put(b5, &quot;3.4&quot;);
  
      System.out.println(trmap);
      int hashcodeb1 = b1.hashCode();
      int hashcodeb2 = b2.hashCode();
  
      System.out.println(&quot;3.1--&gt;&quot; + hashcodeb1);
      System.out.println(&quot;3.10--&gt;&quot; + hashcodeb2);
  }
  </code></pre>
  <p>both hash code are computing the same value my requirement is that I want to put both both values in my map, So with some help of other forum post it looks like I have to override <code>hashCode()</code> method but it returns int as value and I am not sure it will help in my case.</p>
  <p>I have written <code>hashCode()</code> in my class</p>
  <pre><code>public class BigDecimalMap {
      public BigDecimalMap() {
          super();
      }
  
      public static void main(String[] args) {
          BigDecimalMap bigDecimalMap = new BigDecimalMap();
          putKey();
          }
      
          public static void putKey() {
              TreeMap&lt;BigDecimal, String&gt; trmap = new TreeMap&lt;BigDecimal, String&gt;();
              MathContext mc = new MathContext(2);
              BigDecimal b1 = new BigDecimal(3.1, mc);
              BigDecimal b2 = new BigDecimal(3.10, mc);
              BigDecimal b3 = new BigDecimal(3.2, mc);
              BigDecimal b4 = new BigDecimal(3.3, mc);
              BigDecimal b5 = new BigDecimal(3.4, mc);
      
              trmap.put(b1, &quot;3.1&quot;);
              trmap.put(b2, &quot;3.10&quot;);
              trmap.put(b3, &quot;3.2&quot;);
              trmap.put(b4, &quot;3.3&quot;);
              trmap.put(b5, &quot;3.4&quot;);
      
              System.out.println(trmap);
              int hashcodeb1 = b1.hashCode();
              int hashcodeb2 = b2.hashCode();
      
              System.out.println(&quot;3.1--&gt;&quot; + hashcodeb1);
              System.out.println(&quot;3.10--&gt;&quot; + hashcodeb2);
          }
          
          public int hashCode() {
              return 1;
          }
      }
  </code></pre>
  <p>Please help in identifying how to add both values.</p>