Carey Brown wrote:You'd need a method something like this
I'm thinking that you won't want to remove just any-old game from the list. Perhaps you want a HashSet instead of a List.
Carey Brown wrote:You'd need a method something like this
I'm thinking that you won't want to remove just any-old game from the list. Perhaps you want a HashSet instead of a List.
Carey Brown wrote:You'd need a method something like this
I'm thinking that you won't want to remove just any-old game from the list. Perhaps you want a HashSet instead of a List.
Carey Brown wrote:What is the relationship between "course" and "game" ?
Carey Brown wrote:
Justin Robbins wrote:
Carey Brown wrote:
You already have gamesTaking, which is a list of games, just add your new games to that list. However, if gamesTaking is null, then you have to create a new list, add the new game, and put it into the map.
Justin Robbins wrote:
Carey Brown wrote:
You already have gamesTaking, which is a list of games, just add your new games to that list. However, if gamesTaking is null, then you have to create a new list, add the new game, and put it into the map.
Thank you
I don't understand. Why if it's null would I have to create a new list and add a new game then put that into a map?
Could you please explain what this would look like. I know how to create an arraylist but not sure how to add to that list. And how to put into into a map. Really confused here.
Carey Brown wrote:
Justin Robbins wrote:
Carey Brown wrote:
You already have gamesTaking, which is a list of games, just add your new games to that list. However, if gamesTaking is null, then you have to create a new list, add the new game, and put it into the map.
Thank you
I don't understand. Why if it's null would I have to create a new list and add a new game then put that into a map?
Could you please explain what this would look like. I know how to create an arraylist but not sure how to add to that list. And how to put into into a map. Really confused here.
To get the list for a kid: list = map.get(kid); // may return null if no kid in map
To create a new list: list = new ArrayList<String>(); // only necessary if above is null
To put into map: map.put(kid,list); // only necessary if above is null
To add game to list: list.add(game);
Carey Brown wrote:To get the list for a kid: list = map.get(kid); // may return null if no kid in map
To create a new list: list = new ArrayList<String>(); // only necessary if above is null
To put into map: map.put(kid,list); // only necessary if above is null
To add game to list: list.add(game);
Carey Brown wrote:
Carey Brown wrote:To get the list for a kid: list = map.get(kid); // may return null if no kid in map
To create a new list: list = new ArrayList<String>(); // only necessary if above is null
To put into map: map.put(kid,list); // only necessary if above is null
To add game to list: list.add(game);
You are making this too complicated. I suggest that you start your add() method over. The above lines of code, in order, is all you need with the exception of adding in an 'if' statement (no 'else').
Justin Robbins wrote:
Carey Brown wrote:
Carey Brown wrote:To get the list for a kid: list = map.get(kid); // may return null if no kid in map
To create a new list: list = new ArrayList<String>(); // only necessary if above is null
To put into map: map.put(kid,list); // only necessary if above is null
To add game to list: list.add(game);
You are making this too complicated. I suggest that you start your add() method over. The above lines of code, in order, is all you need with the exception of adding in an 'if' statement (no 'else').
Am confused by what list = map.get(kid); means. Is this to say I create a list? when I write list = map.get(kid); I get errors.
I can create a list like: ArrayList<String> list = new ArrayList<String>();
now sure how to go about map.put(kid,list);
Am I suppose to create a separate map somewhere?
Almost there. You haveJustin Robbins wrote:Do you mean the code should look like this:
Yes, but ... If you make the K a mutable type, and it changes its state in such a way that the hash code changes, you will most probably never find it again with get(XXX); A K should be immutable; a String is eminently suitable to be a K. That problem does not apply to the V unless you have a bidirectional HashMap. Types used as Ks need correctly‑overridden hashCode and equals methods.Justin Robbins wrote:. . . and K and V can be any object combination. . . .
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |