Search code examples
javaunicodeemoji

Create string with emoji unicode flag countries


i need to create a String with a country flag unicode emoji..I did this:

StringBuffer sb = new StringBuffer();
sb.append(StringEscapeUtils.unescapeJava("\\u1F1EB"));    
sb.append(StringEscapeUtils.unescapeJava("\\u1F1F7"));

Expecting one country flag but i havent..How can i get a unicode country flag emoji in String with the unicodes characters?


Solution

  • You should be able to do that simply using toChars from java.lang.Character.

    This works for me:

        StringBuffer sb = new StringBuffer();
        sb.append(Character.toChars(127467));
        sb.append(Character.toChars(127479));
        System.out.println(sb);
    

    prints 🇫🇷, which the client can chose to display like a french flag, or in other ways.