java - Questions about contains method in Hash Set -


i high school student apologize terms may misuse.

so making slide puzzle game , working on ai part. have constructor construct board , assign hashcode such 123456780. in a* algorithm, compare if board generate (to find solution) in hashset. use contains method right? how contains method works check if 2 boards identical?.

    public board()     {             board = new int [3][3];             setpieces (board);             hashcode = generatehashcode ();     } 

this 1 of constructor. in board object, have 2d array , hashcode. wonder again, if built-in contains method in hash set compare 2 boards hashcode. or need write one.

also, when assign hash code board, should in constructor right?

thanks you

as you've discovered, need return hashcode object in overridden hashcode() method.

you can either compute hashcode in method, or compute in ctor , store in field, return field in method override.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -