title: Difference between two lists in Java
body: <p>I started learning data structures and algorithms with Java.</p>
  <p>I started with list and the first concept which I learnt is difference between array and list.</p>
  <p>Now in list I learn how to insert and element in to list and displaying on the screen. I got two pieces of code. The first one I understood very well; where the second one is confusing.</p>
  <p>My confusion is what is the <em>Node</em> here? In the beginning we declare <code>Node head;</code>. So basically what is <em>Node</em> here?</p>
  <p>Is it predefined datatype or something? Also, how does the second program flow? How is the second program different from the first? And what is the difference?</p>
  <p>Also I understood that we are using util here, but still I want to know because how people use it in the industry.</p>
  <p>The first method:</p>
  <pre><code>import java.util.*;
  
  public class TestCollection7 {
      public static void main(String args[]) {
  
          LinkedList&lt;String&gt; al = new LinkedList&lt;String&gt;();
          al.add(&quot;Ravi&quot;);
          al.add(&quot;Vijay&quot;);
          al.add(&quot;Ravi&quot;);
          al.add(&quot;Ajay&quot;);
  
          Iterator&lt;String&gt; itr = al.iterator();
          while(itr.hasNext()) {
              System.out.println(itr.next());
          }
      }
  }
  </code></pre>
  <p>Second method:</p>
  <pre><code>package javaapplication3;
  
  public class LIstTEst {
      Node head;
  
      static class Node {
          int data;
          Node next;
          Node(int d) {
              data = d;
              next = null;
          }
      }
  
      public void PrintList() {
          Node n = head;
          while(n != null){
              System.out.print(n.data+&quot; &quot;);
              n = n.next;
          }
      }
  
      public static void main(String args[]) {
          LIstTEst llist = new LIstTEst();
          llist.head = new Node(1);
          Node second = new Node(2);
          Node third = new Node(7);
  
          llist.head.next = second;
          second.next = third; = third;
  
          llist.PrintList();
      }
  }
  </code></pre>