title: Java implementing weighted graph?
body: <p>I had written my code, but don't know how to access weight of graph, or 
  how to print its edges in main method, please have look at my code.
  Please help,actually i trying to implement Dijkstra , but I don't know it is the correct way of including weight in the graph or not. Please help trying to solve it from past three days. </p>
  
  <pre><code>public class Gr {
  
  public class Node{ 
      public int vertex;
      public  int weight ;
  
      public int getVertex() {return vertex;}
      public int getWeight() {return weight;}
      public Node(int v , int w){
          vertex=v;
          weight=w;
      }
  
  }
  private int numVertices=1 ;
  private  int numEdges=0 ;
  private Map&lt;Integer,ArrayList&lt;Node&gt;&gt; adjListsMap= new HashMap&lt;&gt;();
  
  
  public int getNumVertices(){
      return  numVertices;
  }
  
  public int addVertex(){
      int v = getNumVertices();
      ArrayList&lt;Node&gt; neighbors = new ArrayList&lt;&gt;();
      adjListsMap.put(v,neighbors);
      numVertices++ ;
      return (numVertices-1);
  }
  
  //adding edge
  public void addEdge(int u , int v,int w ){
      numEdges++ ;
      if(v&lt;numVertices&amp;&amp;u&lt;numVertices){
          (adjListsMap.get(u)).add( new Node(u,w));
          (adjListsMap.get(v)).add(new Node(u,w));
  
      }
      else {
          throw new IndexOutOfBoundsException();
      }
  }
  
  //getting neighbours
  
  public List&lt;Node&gt; getNeighbors(int v ){
      return new ArrayList&lt;&gt;(adjListsMap.get(v));
  }
  
  
  
  public static void main(String[] args){
      Gr g = new Gr();
  
  
          for(int j=1;j&lt;=3;j++)
              g.addVertex();
          for(int k =1;k&lt;=2;k++)
          {   int u= in.nextInt();
              int v = in.nextInt();
              int w = in.nextInt();
              g.addEdge(u,v,w);
          }
  
  
      }
  </code></pre>
  
  <p>}</p>