Advertisement
JeffGrigg

ZeroLengthCharacter

Apr 15th, 2018
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.28 KB | None | 0 0
  1. public class ZeroLengthCharacter {
  2.     public static void main(String[] args) throws Exception {
  3.  
  4.         final String zeroLengthString = "";
  5.         System.out.println("Zero length string = '" + zeroLengthString + "'");
  6.  
  7.         final char zeroWidthCharacter = '\u200B';
  8.         System.out.println("Zero width character = '" + zeroWidthCharacter + "'");
  9.  
  10.         final String oneCharZeroWidthString = "" + zeroWidthCharacter;
  11.         System.out.println("Single character String with zero display width = '" + oneCharZeroWidthString + "'   (length=" + oneCharZeroWidthString.length() + " char)");
  12.         final byte[] bytes = oneCharZeroWidthString.getBytes("UTF-8");
  13.         System.out.println("  = " + bytes.length + " bytes, when encoded in UTF-8 format.");
  14.  
  15.         System.out.print("Nothing to see here:  '");
  16.         System.out.print("");   // <---<<<  Pointless line of code that doesn't do anything but waste time and space:
  17.         System.out.println("'   Move along.");
  18.     }
  19. }
  20.  
  21. /* Output:
  22.  
  23. ...\java ... ZeroLengthCharacter
  24. Zero length string = ''
  25. Zero width character = '​'
  26. Single character String with zero display width = '​'   (length=1 char)
  27.   = 3 bytes, when encoded in UTF-8 format.
  28. Nothing to see here:  ''   Move along.
  29.  
  30. Process finished with exit code 0
  31.  
  32. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement