String s = "\\"; contains only the \ character, and since it is special, it must be escaped with the \ character.
To get a 2-dimensional string, you can avoid two backslashes, for example:
String s = "\\\\";
This size does not have a size of 4 , but 2 , because there are characters (obviously, like a backslash) that are not represented by a single visual element in the editor.
There are also characters that can be completely invisible when printed (for example, the Mongolian vowel separator ), but which are represented in a different way in the source (by their Unicode code). For example, the Mongolian vowel separator can be represented as:
String mongolianVowelSeparator = "\u180"; <-- one character only, invisible when printed
So, here we have only one character ( U+180E Unicode character), but we used five editor characters to represent it.
source share