title: creating graphs in Java with ArrayLists
body: <p>I'm new to Java and I wanted to practice by creating a graph. I am having trouble creating the graph because I'm not sure how to do so correctly. I am lacking the logic and being new in Java makes things quite difficult. I was wondering if anyone could help me or guide me in the right path! Thanks!</p>
  
  <p>Basically I am trying to create something like this as a graph. A node will contain an <code>ArrayList</code> for it's neighbors. </p>
  
  <pre><code>    A,B,C,D
  A = 0,1,3,0
  B = 1,0,0,2
  C = 1,0,0,3   //shorter path to A (cycle)
  D = 0,0,3,0
  </code></pre>
  
  <p>The nodes are connected to each other with or without weights (if I change numbers to 1)   </p>
  
  <p>Here is what I have so far (it is incomplete):</p>
  
  <pre><code>public class GraphNode {
      boolean visited;
  
  
      public GraphNode() {
          List&lt;GraphNode&gt; node = new ArrayList&lt;GraphNode&gt;();  // store neighbors
          this.visited = false;
  
      }
  
      public void addNeighbor(GraphNode root, GraphNode target, int distance) {
          root.add(target);     // cannot use "add" to ArrayList
  
      }
  }
  </code></pre>