1

For example, is there a way to get the three elements ㄱ, ㅗ, ㅇ from a single Hangeul letter '공'?

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • 3
    Does this answer your question? [Combining accent and character into one character in java 7](https://stackoverflow.com/questions/28873442/combining-accent-and-character-into-one-character-in-java-7) Use the decompose mode with normalizer. – Nicolas Mar 28 '20 at 23:31
  • @Nicolas The answer was very similar, but the question was sort of different, I guess. The linked question was about combining an accent to a character, but mine was getting elements of an Hangeul letter which is formed by combining consonant elements and vowel elements. Anyway, Johannes Kuhn's answer was correct and his note was also helpful, so I chose his answer as the accepted answer. – Damn Vegetables Mar 30 '20 at 01:05
  • The question is different but the answer is the same. AFAIC @Johannes Kuhn basically copied pasted the top answer, changing the character. – Nicolas Mar 30 '20 at 01:10
  • The linked answer is not really a duplicate. It's similar, but definitely very different. Actually, the answer here helped me solve my own problem whereas the linked answer (which I originally found) did not. – Sebbo Jun 22 '22 at 19:12

1 Answers1

4

Use java.text.Normalizer.normalize() with NFD:

String compact = "공";
System.out.println(compact);
String decomposed = Normalizer.normalize(compact, Normalizer.Form.NFD);
System.out.println(Arrays.toString(decomposed.toCharArray()));

Will output

공
[ᄀ, ᅩ, ᆼ]

Note: when you would print decomposed as String (System.out.println(decomposed)) it would print as one character. Or 3. Depends on the output console - if that joins the glyphs.

Johannes Kuhn
  • 14,778
  • 4
  • 49
  • 73