Advertisement
DulcetAirman

codePoints

Jul 19th, 2018
198
0
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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement