java - Custom Class Used in A List/HashSet -


i have custom class looks below:

public class customclass(){     private int keycode;     private boolean up;     private string totrigger;      public string gettrigger();     public boolean up();     public int keycode(); } 

whats best way performance have list of unique values?

i thinking of hashset how make sure unique instances of customclass?

what need override? equals , hashcode? make sure hash set of customclass have unique instances?

thanks

if a.equals(b) true there hashcode() must same.

  • override both .equals() , .hashcode() in custom class.

    use same fields of custom class calculate hashcode used check equality in .equals().

  • yes it'll make sure there unique instances of customclass in hash-set. go it.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -