Is it possible to use the hashmap to implement bfs if it is possible how can i do it? or it is not possible which method should i use instead of hashmap.
Yes it's possible. You are working with an adjacency list. To implement a BFS you will need a queue (there an interface in Java for this). To traverse the graph you start with a single node in your queue, and while this queue is not empty you get the next node and add all the adjacent nodes into your queue, here is where you will need to access your Map
.