0

For a homework assignment which is stated as:

In this homework, you will implement a key-value hash map with a external chaining collision policy. A hash map maps keys to values and allows O(1) average case lookup of a value when the key is known. This hash map must be backed by an array of initial size 11, and must have a size of 2n + 1 when the table exceeds (greater than, not greater than or equal to) a load factor of 0.67. The array must be resized before the new key (regardless of whether or not it’s a duplicate) is actually added into the array. The load factor and initial size values are provided as constants in the interface and should be used within your code.

We're given a MapEntry class already written, and a HashMap class to write up. How would I intialize this array? private MapEntry<K, V>[] table = new MapEntry<>[STARTING_SIZE]; doesn't work because of the generics situation.

3
  • Array or hashmap, which one is it? Theyre not the same Commented Sep 27, 2015 at 16:18
  • @TimCastelijns A HashMap backed by an array, we can't use the Java Object Commented Sep 27, 2015 at 16:20
  • @laune you will implement a key-value hash map with a external chaining collision policy. This hash map must be backed by an array of initial size 11, and must have a size of 2n + 1 when the table exceeds (greater than, not greater than or equal to) a load factor of 0.67. The array must be resized before the new key (regardless of whether or not it’s a duplicate) is actually added into the array. The load factor and initial size values are provided as constants in the interface and should be used within your code. Commented Sep 27, 2015 at 16:22

1 Answer 1

1

You omit the generic parameters in the array constructor:

Map.Entry<String,Integer>[] entries = new Map.Entry[11];

You can use an annotation @SuppressWarnings("unchecked") if the warning bothers you.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay so even though it gives an Unchecked assignment warning it'll still be good?
@newacct Oops. Instant blackout. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.