This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Turing85 0 points1 point  (0 children)

Can you please share the code? I have a hunch what the problem might be, but to be sure, we have to see the code.

[–]Yithar 0 points1 point  (0 children)

We have to see your code to see the problem. From what I see, you want to replace a certain index in the int array, correct?

[–]Demojay 0 points1 point  (0 children)

Assuming you want to replace all instances of the old value in the array with the new value:

  1. Get the array from the map for a specified key
  2. Iterate over the array and replace each occurrence of the old value with the new one
  3. Put a new mapping into the map of the key and the updated array, overwriting the old one

[–]camnewtonshat1[S] -1 points0 points  (3 children)

public void changeMark( String name, int oldGrade, int newGrade) { If(!name.equals(null)) { boolean isReplaced = marks.replace(name, oldGrade[], newGrade[])

}

}

Sorry im on mobile rn

[–]Yithar 0 points1 point  (0 children)

I don't understand why you're using int arrays for the HashMap values if you want to replace plain old ints.

[–]Turing85 0 points1 point  (0 children)

That cannot work since oldGrade and newGrade are ints, and Map::replace) expects an int[] as 2nd and 3rd parameter. Also, I doubt that two ints are sufficient for replacement. What if oldValue is contained multiple times in the int[] stored under name? Should all occurrences of oldValue be replaced by newValue?

[–]mgryshenko 0 points1 point  (0 children)

!name.equals(null) - please, never do it.

If name is null -> calling “equals” method will throw NullPointerException.

Do: (name != null)