trier un tableau de string java
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
final String[] data = new String[] {"Raaata", "Tatatara", "Ratatouille", "Gygyghhhygra", "Bla", "Toto"};
Arrays.sort(data, new Comparator<String>() {
public int compare(String s1, String s2) {
int idx1 = s1.toLowerCase().indexOf("ra");
int idx2 = s2.toLowerCase().indexOf("ra");
if(idx1 == -1) {
idx1 = Integer.MAX_VALUE;
}
if(idx2 == -1) {
idx2 = Integer.MAX_VALUE;
}
Integer i1 = new Integer(idx1);
Integer i2 = new Integer(idx2);
return i1.compareTo(i2);
}
});
System.out.println("Sorted array=" + Arrays.toString(data));
}
}