Showing posts with label unicode. Show all posts
Showing posts with label unicode. Show all posts

Saturday, 30 January 2021

Java12: Unicode support

Unicode 11.0 is the latest version of the Unicode Standard, released on June 5, 2018. Unicode 11.0 adds 684 characters, for a total of 137,374 characters. These additions include 7 new scripts, for a total of 146 scripts, as well as 66 new emoji characters.

 

Unicode11Example.java

package com.sample.app.strings;

public class Unicode11Example {
	public static void main(String args[]) {
		String emoji1 = "\uD83E\uDD76";
		String emoji2 = "\uD83E\uDD81";
		String emoji3 = "\uD83E\uDD85";
		
		System.out.println(emoji1 + " " + emoji2 + " " + emoji3);
	}

}

Output

🥶 🦁 🦅

 

Reference

https://unicode.org/versions/Unicode11.0.0/

https://home.unicode.org/emoji/


  

Previous                                                    Next                                                    Home

Saturday, 8 February 2020

Convert UTF-16 unicode characters to UTF-8 in java

Step 1: Get UTF_8 byte array from utf16 unicode string
String utf16EncodedChars = "\u0048 \u0065 \u006c \u006c \u006f \u0020 \u0057 \u006f \u0072 \u006c \u0064";
byte[] utf8Bytes = utf16EncodedChars.getBytes(StandardCharsets.UTF_8);

Step 2: Get the string object from byte array.
String result = new String(utf8Bytes, StandardCharsets.UTF_8);

App.java
package com.sample.app;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

public class App {

 public static void main(String args[]) throws UnsupportedEncodingException {
  String utf16EncodedChars = "\u0048 \u0065 \u006c \u006c \u006f \u0020 \u0057 \u006f \u0072 \u006c \u0064";

  byte[] utf8Bytes = utf16EncodedChars.getBytes(StandardCharsets.UTF_8);

  String result = new String(utf8Bytes, StandardCharsets.UTF_8);

  System.out.println(result);
 }

}

Output
H e l l o   W o r l d


You may like