Steffan Harris
Steffan Harris

Reputation: 9326

How to edit a java map

I have a simple question about a java map.Suppose I have a map that has a key and value already set. How do I change the value of that key; what method would I use?

Upvotes: 3

Views: 3048

Answers (2)

EboMike
EboMike

Reputation: 77752

I suppose you're referring to the java.util.Map class? You can simply use put() - it will replace an existing value if that key has already been set.

Upvotes: 2

Kaleb Brasee
Kaleb Brasee

Reputation: 51945

Just call a normal put -- it will replace the existing value for the key. If you need to access the old value for that key, the put method returns it.

See the javadoc for more details.

Upvotes: 5

Related Questions