containsKey(),而不用get():

HashMap中,null可以作为键,这样的键只有一个;可以有一个或多个键所对应的值为null。当get()方法返回null值时,即可以表示HashMap中没有该键,也可以表示该键所对应的值为null。因此,在HashMap中不能由get()方法来判断HashMap中是否存在某个键,而应该用containsKey()方法来判断。

相关文章:

  • 2022-01-07
  • 2021-12-07
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2022-01-07
  • 2022-01-30
  • 2021-07-11
  • 2022-12-23
  • 2021-06-11
  • 2021-12-04
相关资源
相似解决方案