title: Generic method returning ArrayList
body: <p>I am trying to make a program that creates an ArrayList given the type as well as the values that will be put into the ArrayList. The input structure that we have to work with is "I 6 7 5 3 1 -1 2" with the I being the type Integer (or S for String, etc) and the first number (6) being how many values are in the ArrayList. I'm not sure how to instantiate the ArrayList.</p>
  
  <pre><code>public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String type = scan.next();
      int length = scan.nextInt();
      int counter = 0;
  
      if (type.equals("I")) {
          ArrayList&lt;Integer&gt; A = new ArrayList&lt;Integer&gt;;
      }
      else if (type.equals("S")) {
          ArrayList&lt;String&gt; A = new ArrayList&lt;String&gt;;
      }
      else if (type.equals("D")) {
          ArrayList&lt;Double&gt; A = new ArrayList&lt;Double&gt;;
      }
      else {
          System.out.println("Invalid type");
      }
  
      while (scan.hasNext() &amp;&amp; counter&lt;length) {
          String s1 = scan.next();
          A.add(s1);
          counter += 1;
      }
  
      System.out.print(A);
  }
  
  //Removes any duplicate values in the arraylist by checking each value after it
  public static &lt;E&gt; ArrayList&lt;E&gt; removeDuplicates(ArrayList&lt;E&gt; list) {
      ArrayList&lt;E&gt; inArray = list;
      for (int i = 0; i&lt;inArray.size(); i++) {
          for (int j = i+1; j&lt;inArray.size(); j++) {
              if (inArray.get(i) == inArray.get(j)) {
                  inArray.remove(j);
              }
          }
      }
      return inArray;
  }
  
  //Shuffles the contents of the array
  public static &lt;E&gt; void shuffle(ArrayList&lt;E&gt; list) {
      E temp;
      int index;
      Random random = new Random();
      for (int i = list.size()-1; i &gt; 0; i--) {
          index = random.nextInt(i + 1);
          temp = list.get(index);
          list.set(index, list.get(i));
          list.set(i, temp);
      }
      System.out.print(list);
      return;
  }
  
  //Returns the largest element in the given arraylist
  public static &lt;E extends Comparable&lt;E&gt;&gt; E max(ArrayList&lt;E&gt; list) {
      E max = Collections.max(list);
      System.out.println(max);
      return max;
  }
  </code></pre>