Sorting java arrayList with predefined order
<p>I have an unsorted list but I want to sort in a custom way i.e.</p>

<pre><code>item_one_primary.pls
item_one_secondary.pls
item_one_last.pls

item_two_last.pls
item_two_primary.pls
item_two_secondary.pls

item_three_secondary.pls
item_three_last.pls
item_three_primary.pls
</code></pre>

<p>Here is my predefined order : <code>primary, secondary, last</code></p>

<p>Above unordered list once the ordering is applied should look like this :</p>

<pre><code>item_one_primary.pls
item_one_secondary.pls
item_one_last.pls

item_two_primary.pls
item_two_secondary.pls
item_two_last.pls

item_three_primary.pls
item_three_secondary.pls
item_three_last.pls
</code></pre>

<p>I tried something with comparator but I end up something like this :</p>

<pre><code>item_one_primary.pls
item_two_primary.pls
item_three_primary.pls
</code></pre>

<p>...</p>

<p>Does anyone have an idea how to get this sorted?</p>

<p>Here is some code I've used :</p>

<pre><code>List&lt;String&gt; predefinedOrder;

public MyComparator(String[] predefinedOrder) {
        this.predefinedOrder = Arrays.asList(predefinedOrder);
    }

@Override
    public int compare(String item1, String item2) {
        return predefinedOrder.indexOf(item1) - predefinedOrder.indexOf(item2);
    }   
</code></pre>

<p>I didn't include the splits(first split by dot(.) second split by underscore(_) to get the item in pre-ordered list). </p>
