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

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

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