Quiero ordenar un ArrayList<String>
pero el problema es mis caracteres en el idioma nativo - mi alfabeto es el siguiente: a, ą, b, c, č, d, e, f ... z, ž
. Como ve z
el carácter es el segundo desde el final y ą
es el segundo en el alfabeto, por lo que después de ordenar mi matriz, se ordena de forma incorrecta. Todos mis caracteres en el idioma nativo se mueven al final de la matriz. Ejemplo:Matriz de Java ordenar UTF-8
package lt;
import java.util.ArrayList;
import java.util.Collections;
public class test {
public static void main(String[] args) {
List<String> items = new ArrayList<>();
items.add("bbc");
items.add("ąbc");
items.add("abc");
items.add("zzz");
System.out.println("Unsorted: ");
for(String str : items) {
System.out.println(str);
}
Collections.sort(items);
System.out.println();
System.out.println("Sorted: ");
for(String str : items) {
System.out.println(str);
}
}
}
Salida:
Unsorted:
bbc
ąbc
abc
zzz
Sorted:
abc
bbc
zzz
ąbc
debe ser:
Sorted:
abc
ąbc
bbc
zzz
Ver [esta pregunta] (http://stackoverflow.com/questions/4225523/collator-doesnt-sort-right-for-given-locale) –