title: Queue implementation with Generics in Java
body: <p>trying to make an immutable queue and performing standard queue operations on it,using generics.the problem is i dont know much about generics :( please bear with me about the flow and structure of the code</p>
  
  <p>so far i have </p>
  
  <pre><code>import java.lang.*;
  import.java.util.*;
  import java.util.NoSuchElementException;
  
  public class ImmutableQueue&lt;E&gt;
  {
    private final List&lt;E&gt; elmnts;
  
     public ImmutableQueue(List&lt;E&gt; elmnts) 
      {
       this.elmnts = elmnts;
       return elmnts.newInstance(); 
      }
  
    public ImmutableQueue() 
    {
      elmnts = new LinkedList&lt;E&gt;();
    }
  
   public ImmutableQueue&lt;E&gt; enqueue(E e)
   {
      if(e.equals("null"))
        throws IllegalArgumentException;
  
      List&lt;E&gt; copy = new LinkedList&lt;E&gt;(elmnts);
      copy.add(elmnts);
      copy.addlast(e);
      Iterator iterator = copy.iterator();
      while(iterator.hasNext())
       {
         Object prnt = itr.next();
         System.out.println(prnt+" ");
       }
     }
  
    public ImmutableQueue&lt;E&gt; dequeue()
    {
       if (elmnts.size() == 0) 
       {
        throw new NoSuchElementException();
       }
  
      List&lt;E&gt; copy = new LinkedList&lt;E&gt;(elmnts);
      copy.add(elmnts);
      copy.remove(0);
  
      Iterator iterator = copy.iterator();
       while(iterator.hasNext())
        {
         Object prnt = itr.next();
         System.out.println(prnt+" ");
        }
    } 
  
    public E peek()
    {
      String fsel=elmnts.get(0);
      System.out.println("First Element in the Queue is "+fsel);
      return null;
     }
  
    public int size()
    {
      int size=0;
      Iterator iterator = elmnts.iterator();
       while(iterator.hasNext())
       {
        size++; 
       }
      return size;
    }
  
  
       public static void main(String [] arg)
       {
          int a;
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in)) ;
  
          ImmutableQueue&lt;E&gt; imqu=new LinkedList&lt;E&gt;();
  
          System.out.println("Create Queue/Add Elements to Queue ? ('N' or 'n' to stop)");
         &lt;E&gt; e=br.readLine();
  
         while(e!='n' || e!='N')
         {  
          imqu.insert(e);
         }
  
        System.out.println(":: Queue Operations ::");
        System.out.println("\n\n\n21.Enqueue\n2.Dequeue\n3.Peek\n4.size");
  
        a=Integer.parseInt(br.readLine());
        System.out.println("Choice"+a); 
  
      switch(a)
      {
       case 1: System.out.println("Element to be Enqueued : ");
               &lt;E&gt; el=br.readLine();
               imqu.enqueue(E el);
               break;
  
       case 2: imqu.dequeue();
               break;
  
       case 3: imqu.peek();
               break;
  
       case 4: int sz=imqu.size();
               System.out.println("Size of the queue is"+sz);
               break;
  
       default: System.out.println("Bad Choice");
  
      }
   }
  }
  </code></pre>
  
  <p>thanks</p>