Scala map isDefinedAt() vs contains() method

Viewed 1814

Below is my HashMap:

val params1 = collection.mutable.HashMap[String, Any]()

params1 += "forCourseId" -> "2"

println(params1.isDefinedAt("forCourseId"))

println(params1.contains("forCourseId"))

What is difference between isDefinedAt() & contains() method?

I need to check whether key is present or not main concern is , it will not throw null pointer exception.

2 Answers
Related