Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should override hashcode and equals method of Object class in your PlayerNames class.</p> <p>As you want to get on basis of OrigName instance variable only only so use only this in hashcode method while calculating hashcode and in equals method while comparison.</p> <p>EDIT: Updated your class</p> <p>class PlayerNames {</p> <pre><code> String OrigName; String TagName; //String DispName; PlayerNames(String OrigName,String TagName) { this.OrigName = OrigName; this.TagName = TagName; //this.DispName = DispName; } @Override public boolean equals(Object o){ if(o instanceof PlayerNames){ PlayerNames p = (PlayerNames)o; return ( p.OrigName == this.OrigName); } else return false; } @Override public int hashCode(){ int hashcode=0; int MOD=10007; int shift=29; for(int i=0;i&lt;OrigName.length();i++){ hashcode=((shift*hashcode)%MOD+OrigName.charAt(i))%MOD; } return hashcode; } @Override public String toString(){ return OrigName; } } </code></pre> <p>For put and get operations I have written below class</p> <pre><code>import java.util.HashMap; public class MainThread { public static void main(String[] args) { PlayerNames Bob = new PlayerNames(new String("Bob"),new String("BobsWindshield")); HashMap&lt;PlayerNames, Integer&gt; PlayerTempNeutral = new HashMap&lt;PlayerNames, Integer&gt;(); PlayerTempNeutral.put(Bob,100); Integer p = PlayerTempNeutral.get(Bob); System.out.println(p); } } </code></pre> <p>Use above code for experiment purpose only , as it is a bad coding practice. As you are a new java programmer understanding concepts is more important then best practice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload