I always think that line.separatorperforms the same actions as \n, and yes, that . but I noticed that both values actually don't match (maybe they don’t even close?) when I check this code:
String str1 = System.getProperty("line.separator");
String str2 = "\n";
System.out.println(str1.equals(str2));
Then I checked the length of both:
System.out.println(str1.length());
System.out.println(str2.length());
I wonder why str1.length()there is 2, I tried this:
System.out.println("**"+str1.charAt(0)+"**");
exit:
**
System.out.println("##"+str1.charAt(1)+"##");
exit:
#
#
So, I noticed that the actual newline character in line.separatoris the second character. Then what is the value in the first index, since when it should print ****(at least), it prints instead **?
source
share