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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -