Adjacency List Creation in java

I have 2 doubts

  1. how to create adjacency list when graph is weighted
    graph[x].add(y) how to add weight ?
  2. Want to know how adjacency list will be initialized using hashmap in java for weighted graph.

@bugfreecoder hey,when you have weight also ,then take two elements as pair in value of hashmap regarding to particular key so when a and b node have edge weighted w then a key will have b and w as its value pair ,here isthe code for reference in java:

Where is the link for java code ?

@bugfreecoder hey ,here is code:

I need code for creating adjacency list using HashMap in java

@bugfreecoder hey please try that yourself ,in place of list you have to take hashmap ,try it you will get it and get to learn a lot.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.