Question: I know there are other questions about the general best practices while over riding hashCode and equals, but I have a very specific question. 

I have a class that has as an instance variable, an array of the same class. To be more explicit, here's the code:

```
Class Node{
    Node arr[] = new Node[5];
}

```

I need to overwrite hashCode for the class Node, and the array is an important, deciding factor in determining whether two Nodes are the same. How can I incorporate the array into the calculation of hashCode effectively?

--Edit--

I'm trying to check if the two nodes are the same, meaning that they have the same number of children, and that those children lead to the exact same states. Therefore, I'm effectively trying to compare the subtrees at the two node. I'm wondering if I can use hashing to do this equality check. 

I think I actually need to hash the entire subtree, but I'm not sure how I'd go about doing that given the recursive nature of my class definition.

Answer: 
You can use `Arrays.hashCode()` and `Arrays.equals()` methods.
A few of points to add to the current answers, if performance is of any concern.

First, you need to decide whether *order* of the child nodes in a node matter. If they don't, you cannot use the hashcode for an array. Consider fashioning your hashcode function around that defined by `java.util.Set`. Also consider using some ordering internally to improve equals performance. For example, if the subtrees' depths/heights differ, you can sort by depth.

Second, if your subtrees are deep, your hashcode can get very expensive. So I would cache the hashcode, and compute it upon construction (if your node is immutable), or invalidate upon mutation and re-calculate on demand.

Third, if your subtrees are deep, check the hashcode in equals() and return false early. Yes, hashcode is inspected by Map implementations, but there are places where code simply compares two objects using equals(), and they may pay a big price.

Finally, consider using Arrays.asList() (if child ordering matters) or HashSet (if ordering doesn't matter and no two child nodes are equal) instead of a simple array. Then equals and hashcode are reduced to delegating the call to the container instance... with appropriate caching of hashcode, of course.