Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ZeroLengthCharacter {
- public static void main(String[] args) throws Exception {
- final String zeroLengthString = "";
- System.out.println("Zero length string = '" + zeroLengthString + "'");
- final char zeroWidthCharacter = '\u200B';
- System.out.println("Zero width character = '" + zeroWidthCharacter + "'");
- final String oneCharZeroWidthString = "" + zeroWidthCharacter;
- System.out.println("Single character String with zero display width = '" + oneCharZeroWidthString + "' (length=" + oneCharZeroWidthString.length() + " char)");
- final byte[] bytes = oneCharZeroWidthString.getBytes("UTF-8");
- System.out.println(" = " + bytes.length + " bytes, when encoded in UTF-8 format.");
- System.out.print("Nothing to see here: '");
- System.out.print(""); // <---<<< Pointless line of code that doesn't do anything but waste time and space:
- System.out.println("' Move along.");
- }
- }
- /* Output:
- ...\java ... ZeroLengthCharacter
- Zero length string = ''
- Zero width character = ''
- Single character String with zero display width = '' (length=1 char)
- = 3 bytes, when encoded in UTF-8 format.
- Nothing to see here: '' Move along.
- Process finished with exit code 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement