title: Shifting in arrayList
body: <p>The method  <code>public static &lt;T&gt; ArrayList&lt;T&gt; rotate(ArrayList&lt;T&gt; aL, int shift)</code> accepts an <code>Arraylist</code> of String (at least in this example) and a <code>shift</code> which indicated how much the arraylist should shift. If I have, let's say an arayList of</p>
  <pre><code>[ A, B, C, D, E, F, G] 
  </code></pre>
  <p>and the shift is <code>2</code>, so the method returns</p>
  <pre><code>[ F, G, A, B, C, D, E]
  </code></pre>
  <p>or another example,</p>
  <pre><code>[ A, B, C, D, E, F, G]
  </code></pre>
  <p>and <code>shift</code> is <code>4</code>, then the method returns</p>
  <pre><code>[ D, E, F, G, A, B, C] 
  </code></pre>
  <p>I did the method completely wrong and have no clue how to approach this problem. Could smb help me with that ?</p>
  <pre><code>import java.util.ArrayList;
  public class Rotation{
    // Demonstrate rotat(a,shift) method
    public static void main(String arg[]){
      ArrayList&lt;Character&gt; charsL;
      charsL = new ArrayList&lt;Character&gt;();
      char [] chars = { 'A', 'B', 'C',
                        'D', 'E', 'F'};
      for(char c : chars){
        charsL.add(c);
      }
      // charsL = [ A, B, C, D, E, F]
  
      ArrayList&lt;Character&gt; result1;
  
      result1 = rotate(charsL, 2);
      // result1== [ E, F, A, B, C, D]
      System.out.println(result1);
      
      result1 = rotate(charsL, 7);
      // result1== [ F, A, B, C, D, E]
      System.out.println(result1);
  
      // WORKS WITH SRTINGS TOO
      ArrayList&lt;String&gt; stringL;
      stringL = new ArrayList&lt;String&gt;();
      String [] strs = { &quot;A&quot;, &quot;B&quot;, &quot;C&quot;,
                         &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;G&quot; };
      for(String s : strs){
        stringL.add(s);
      }
      // stringL = [ A, B, C, D, E, F, G]
  
      ArrayList&lt;String&gt; result2;
  
      result2 = rotate(stringL, 7);
      // result2== [ A, B, C, D, E, F, G]
      System.out.println(result2);
  
      result2 = rotate(stringL, 4);
      // result2== [ D, E, F, G, A, B, C]
      System.out.println(result2);
    }
  
    public static &lt;T&gt;
    ArrayList&lt;T&gt; rotate(ArrayList&lt;T&gt; aL, int shift){
      // YOUR DEFINITION HERE 
        
        ArrayList &lt;T&gt; newValues = new ArrayList&lt;&gt;();
        ArrayList &lt;T&gt; temp = new ArrayList&lt;&gt;();
        
        for(int i = 0; i &lt; aL.size(); i++)
        {
            newValues.remove(aL.get(shift));
            newValues.add(aL.get(i));
           //newValues.add(shift, aL.get(i));
            
        }
        return newValues;
  
    }
  
  }
  </code></pre>