title: Fastest Way To Implement A Queue in Java
body: <p>I wanted to know what changes should I be making to this code to reduce its execution time.</p>
  
  <pre><code>import java.util.*;
  
  public class ExamPeekableQueueImpl &lt;E extends Comparable&lt;E&gt;&gt; implements ExamPeekableQueue&lt;E&gt; {
  
      LinkedList&lt;E&gt; li = new LinkedList&lt;E&gt;();
  
      public ExamPeekableQueueImpl(){
      }
  
      public void enqueue(E e){
          if(li.isEmpty()){
              li.add(0, e);
          }
          else
          li.add(e);
      }
  
      public E dequeue(){
          li.pollFirst();
          return null;
      }
  
      public void printlist(){
          System.out.println(li.toString());
      }
  
      public E peekMedian(){
          int var = (((li.size())/2)+1);
          Collections.sort(li);
          //Integer var2 = li.get(var);
          System.out.println("the median is:" + li.get(var-1));
          return null;
      }
  
      public E peekMaximum(){
          Collections.sort(li);
          System.out.println("the maximum is:" + li.getLast());
          return null;
      }
  
      public E peekMinimum(){
          Collections.sort(li);
          System.out.println("the minimum is:" + li.getFirst());
          return null;
      }
  
      public int size(){
          li.size();
          return 0;
      }   
  }
  </code></pre>
  
  <p>Also I wanted to know is whether for implementing <code>queues</code>, <code>LinkedList</code> is faster or <code>ArrayList</code> or any other data structure.</p>