SHARE
TWEET

codePoints

DulcetAirman Jul 19th, 2018 (edited) 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.nio.charset.Charset;
  2. import java.nio.charset.StandardCharsets;
  3. import java.util.Scanner;
  4.  
  5. public class SomeClass {
  6.  
  7.   public static void main(String[] args) {
  8.  
  9.     Charset charset = Charset.defaultCharset();
  10.     System.out.print("Used charset: ");
  11.     System.out.println(charset);
  12.     if (!charset.contains(StandardCharsets.UTF_8))
  13.       System.out.println("Warning: It does not contain all unicode characters!");
  14.  
  15.     try (Scanner scanner = new Scanner(System.in, charset)) {
  16.       System.out.println("enter some characters and hit <enter> to know their Unicode code points");
  17.       String str = scanner.nextLine();
  18.       str.codePoints().forEach(cp -> {
  19.         System.out.print(new String(Character.toChars(cp)));
  20.         System.out.print(": ");
  21.         System.out.println(cp);
  22.       });
  23.     }
  24.   }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top