Alex Rivera | Logout

Map with key only - for contains checking

Asked 2012-11-25T07:32:30.110
10

I have to store a close list for this I defined a Map -

Map<Node, Boolean> closeList = new HashMap<Node, Boolean>()

now for checking whether a node is exist in this map I use -

boolean binExists = closeList .containsKey(node)

seems that the value-boolean of the map is unnecessary .

Have you any better idea for this check using HashMap mode (O(1)) ?

Edit
Report

1 Answer

0

With ArrayList you can get the following in O(1):

  • size
  • isEmpty
  • get
  • set
  • iterator
  • listIterator

With HashSet you can get the following in O(1):

  • add
  • remove
  • contains
  • size
answered 2012-11-25T08:01:30.523

Your Answer