Constructing a tree, where for every node, its adjacant nodes are known
<p>I am new to java. I want to construct a tree, where for every node, the adjacent nodes(children) are known. The adjacent nodes for every node are found out using the below code. </p>

<p>Please help me out.!!</p>

<pre><code>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Node{
    int node_x;
    int node_y;
    String name;
    ArrayList adjList;
    String data;

        Node(){}
    Node(int x, int y){
        node_x=x;
        node_y=y;
    }
}


public class Graphs {
    void insertVertices() throws IOException
    {

        Node[][] g=new Node[8][8];
        for (int i = 0; i &lt; 8; i++) {
           for (int j = 0; j &lt; 8; j++) {
              g[i][j]=new Node();
              g[i][j].node_x=i;
              g[i][j].node_y=j;
              g[i][j].name="a"+Integer.toString(i)+Integer.toString(j);
           }
        }
       for (int i = 0; i &lt; 8; i++) {
           for (int j = 0; j &lt; 8; j++) {
              g[i][j].adjList= new ArrayList();
              g[i][j].adjList.add("a"+Integer.toString(i+1)+Integer.toString(j));
              g[i][j].adjList.add("a"+Integer.toString(i)+Integer.toString(j+1));
             if(i-1 &gt;=0){
              g[i][j].adjList.add("a"+Integer.toString(i-1)+Integer.toString(j));
             }
             if(j-1&gt;=0){
              g[i][j].adjList.add("a"+Integer.toString(i)+Integer.toString(j-1));
             }
           }
        }
       for (int i = 0; i &lt; 8; i++) {
           for (int j = 0; j &lt; 8; j++) {
               System.out.println(g[i][j].node_x);
               System.out.println(g[i][j].node_y);
               System.out.println(g[i][j].name);
               System.out.println(g[i][j].adjList);
               System.out.println("*************************");
           }
       }


    }

    public static void main(String[] args) throws IOException {
             new Graphs().insertVertices();
    }

}
</code></pre>

<p>The output is- for every node, its adjacant nodes are saved in a list. </p>
