Find duplicate strings in list and make them unique
<p>I have an <code>ArrayList</code> with duplicate string values and want to make the duplicates unique by appending a count.</p>

<pre><code>public static void main(String[] args) {
    List&lt;String&gt; list = new ArrayList&lt;String&gt;();
    list.add("a");
    list.add("b");
    list.add("c");
    list.add("d");
    list.add("b");
    list.add("c");
    list.add("a");
    list.add("a");
    list.add("a");

    HashSet&lt;String&gt; set = new HashSet&lt;String&gt;();
    List&lt;String&gt; duplicateList = new ArrayList&lt;String&gt;();

    for (String item : list) {
        // If String is not in set, add it to the list and the set.
        if (!set.contains(item)) {              
            set.add(item);
        } else {
            duplicateList.add(item);
        }
    }

    for (String element : duplicateList) {
        System.out.println(element);
    }
}
</code></pre>

<p>Is there any way to make the list like:</p>

<pre><code>a
b
c
d
b1
c1
a1
a2
a3
</code></pre>