title: Sort a list of hungarian strings in the hungarian alphabetical order
body: <p>I am working at the moment with some data in hungarians.
  I have to sort a list of hungarians strings.</p>
  
  <p>According to <a href="http://en.wikipedia.org/wiki/Collating_sequence" rel="noreferrer">this Collation Sequence page</a></p>
  
  <blockquote>
    <p>Hungarian alphabetic order is: A=Á, B, C, CS, D, DZ, DZS, E=É, F, G,
    GY, H, I=Í, J, K, L, LY, M, N, NY, O=Ó, Ö=Ő, P, Q, R, S, SZ, T, TY,
    U=Ú, Ü=Ű, V, W, X, Y, Z, ZS</p>
  </blockquote>
  
  <p>So vowels are treated the same (A=Á, ...) so in the result you can have some like that using <a href="http://download.oracle.com/javase/6/docs/api/java/text/Collator.html" rel="noreferrer">Collator</a> :</p>
  
  <pre><code>Abdffg
  Ádsdfgsd
  Aegfghhrf
  </code></pre>
  
  <p>Up to here, no problem :)</p>
  
  <p>But now, I have the requirement to sort according to the <a href="http://en.wikipedia.org/wiki/Hungarian_alphabet" rel="noreferrer">Hungarian alphabet</a> </p>
  
  <blockquote>
    <p>A Á B C Cs D Dz Dzs E É F G Gy H I Í J K L Ly M N Ny O Ó Ö Ő P (Q) R S
    Sz T Ty U Ú Ü Ű V (W) (X) (Y) Z Zs</p>
  </blockquote>
  
  <p>A is considered different than Á</p>
  
  <p>Playing with the <a href="http://download.oracle.com/javase/6/docs/api/java/text/Collator.html#setStrength%28int%29" rel="noreferrer">Strength</a> from <code>Collator</code> doesnt change the order in the output. A and Á are still mixed up.</p>
  
  <p>Is there any librairies/tricks to sort a list of string according to the hungarian alphabetical order?</p>
  
  <p>So far what I am doing is :</p>
  
  <ul>
  <li>Sort with <code>Collator</code> so that the C/Cs, D,DZ, DZS... are sorted correctly</li>
  <li>Sort again by comparing the first characters of each word based on a map</li>
  </ul>
  
  <p>This looks too much hassle for the task no?</p>
  
  <pre><code>List&lt;String&gt; words = Arrays.asList(
          "Árfolyam", "Az",
          "Állásajánlatok","Adminisztráció",
          "Zsfgsdgsdfg", "Qdfasfas"
  
  );
  
  final Map&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();
        map.put("A",0);
        map.put("Á",1);
        map.put("E",2);
        map.put("É",3);
  
        map.put("O",4);
        map.put("Ó",5);
        map.put("Ö",6);
        map.put("Ő",7);
  
        map.put("U",8);
        map.put("Ú",9);
        map.put("Ü",10);
        map.put("Ű",11);
  
  
        final Collator c = Collator.getInstance(new Locale("hu"));
        c.setStrength(Collator.TERTIARY);
        Collections.sort(words, c);
  
        Collections.sort(words, new Comparator&lt;String&gt;(){
            public int compare(String s1, String s2) {
  
                int f = c.compare(s1,s2);
                if (f == 0) return 0;
  
                String a = Character.toString(s1.charAt(0));
                String b = Character.toString(s2.charAt(0));
  
                if (map.get(a) != null &amp;&amp; map.get(b) != null) {
                    if (map.get(a) &lt; map.get(b)) {
                        return -1;
                    }
                    else if (map.get(a) == map.get(b)) {
                        return 0;
                    }
                    else {
                        return 1;
                    }
                }
  
  
                return 0;
            }
        });
  </code></pre>
  
  <p>Thanks for your input</p>