Chapter 4. Core APIs and indent().
Would be grateful if someone can confirm if I understood my
test example based on a content from book.
Their explanation:
Line 16 counts the six characters in block, which are the three letters, the blank space before b, and the \n after a and b. Line 17, we ask Java to add a single blank space to each of the three lines in block.
However, the output says we added 4 characters rather than 3 since the length went from 6 to 10. This mysterious additional character is thanks to the line termination normalization. Since the text block doesn’t have a line break at the end, indent() adds one!
My text block:
My explanation why length is 14.
We will have six rows, as follow:
Row1: whitespace + a+\n =>>> 3 char total. \n is added manually, so text block doesn't add another \n
Row2: whitespace +\n =>>> 2 char total. whitespace is added because of indent() and \n is added implicitly by the Java/text block
Row3: whitespace + whitespace + b + \n =>>> 4 char total. \n is added manually, so text block doesn't add another \n
Row4: whitespace + \n =>>> 2 char total. whitespace is added because of indent() and \n is added implicitly by the Java/text block
Row5: whitespace + c + \n =>>> 3 char total. Since
string is ending with \n indent() doesn't add it
Row6: empty =>>> 0 char total.