Removing shorter strings not working
<p>Write a method <code>removeShorterStrings</code> that takes an <code>ArrayList&lt;String&gt;</code> as a parameter and that removes from each successive pair of values the shorter string in the pair.</p>

<p>For example, suppose that an <code>ArrayList</code> called <code>list</code> contains the following values: <code>{"four", "score", "and", "seven", "years", "ago"}</code></p>

<p>In the first pair, <code>"four"</code> and <code>"score"</code>, the shorter string is <code>"four"</code>.<br>
In the second pair, <code>"and"</code> and <code>"seven"</code>, the shorter string is <code>"and"</code>.<br>
In the third pair, <code>"years"</code> and <code>"ago"</code>, the shorter string is <code>"ago"</code>.</p>

<p>Therefore, the call: <code>removeShorterStrings(list);</code> should remove these shorter strings, leaving the list as follows: <code>{"score", "seven", "years"}</code>.</p>

<p>If there is a tie (both strings have the same length), your method should remove the first string in the pair. If there is an odd number of strings in the list, the final value should be kept in the list.</p>

<pre><code>public void removeShorterStrings(ArrayList &lt;String&gt; a){
   
    for(int i=0;i&lt;a.size()-1;i+=2){
        String word=a.get(i);
        String word2=a.get(i+1);
        
        if(a.size()%2==0 &amp;&amp; word.length()&lt;word2.length()){
           a.remove(i);
            if(word.length()==word2.length()){
                a.remove(i);
            }
        }
    }
}
</code></pre>

<p>called for <code>["four", "score", "and", "seven", "years", "ago"]</code>.</p>

<p>My code gives me <code>[score, and, seven, years, ago]</code> instead of <code>[score, seven, years]</code>.</p>

<p>What's the problem?</p>
