Quidditch – Part 4
Prerequisite: You finished the lesson:
equalobjects must share the same
When you add an
equals() method, you must also add a
hashCode() method that assigns equal objects the same hashCode.
hashCodeto find which bucket the key is in.
- After it finds the bucket,
equals()can compare your object against the key.
Team.java, add a
hashCode method that assigns equal objects the same
Objects.hash() doesn't work with arrays. Pass the
chasers field in as a
Task 2: Test your code
getScoreshould return the score 0.
setScoreshould update gryffindor's score.
You will retrieve the
Team key that matches the
- You can run through
key-valuepairs as an
forEachruns through every entry.
- Each entry contains a key and value.
- You can also run through each
Task: Choose to run an
keySet through a stream pipeline. Then, choose one of the following pipelines to return the matching key:
There are four possible ways to approach this problem. Only do one. The solution video will cover all four implementations.
entrySet, the stream is a sequence of entries.
keySet, the stream is a sequence of keys.
- For pipeline 2, collect should return a list with only one element.
- Indexing a
Listis the same as
main(), fetch the object named
"GRYFFINDOR". Then, print the object that it returns.
static variable called
gameCount that counts up every time there's a