From: gu.martinm@gmail.com Date: Wed, 26 Mar 2014 13:08:43 +0000 (+0100) Subject: String collation, Java example X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5b10f73c1f695542ee2d878a591362d7f274b89a;p=JavaForFun String collation, Java example --- diff --git a/Allgemeines/UNICODECollation/src/de/example/collation/CollationExample.java b/Allgemeines/UNICODECollation/src/de/example/collation/CollationExample.java new file mode 100644 index 0000000..1d728b1 --- /dev/null +++ b/Allgemeines/UNICODECollation/src/de/example/collation/CollationExample.java @@ -0,0 +1,29 @@ +package de.example.collation; + +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +public class CollationExample { + + + public static void main(final String[] args) { + final String[] words = {"cote", "coté", "côte", "côté"}; + + final List wordsListES = new ArrayList(Arrays.asList(words)); + final List wordsListFR = new ArrayList(Arrays.asList(words)); + + final Collator es_ESCollator = Collator.getInstance(new Locale("es","ES")); + final Collator fr_FRCollator = Collator.getInstance(Locale.FRANCE); + + Collections.sort(wordsListES, es_ESCollator); + Collections.sort(wordsListFR, fr_FRCollator); + + System.out.println("Words list ES: " + wordsListES); + System.out.println("Words list FR: " + wordsListFR); + } + +}