First, the processing of the array of println methods is first converted to string type, we can enter the println source code look, I was creating a string array to look at the next
public void println (Object x) {
String s = string.valueof (x);
Synchronized (this) {
print (s);
NewLine ();
}
First he turns into a string and then goes into the Print method
public void print (String s) {
if (s = = null) {
s = ' null ';
}
Write (s);
}
Next, we'll go into the write method.
private void Write (String s) {
try {
synchronized (this) {
ensureopen ();//confirm that the output stream is open
textout.write (s) ;//is a bufferwriter, write to the buffer
textout.flushbuffer ();//Refresh Buffer
charout.flushbuffer ();//outputstreamwriter
if (AutoFlush && (s.indexof (' \ n ') >= 0))
Out.flush ()//Here is the one with the char array, and he flushes the string s to the output stream of the console. But remember he didn't have to ToString Method-
associated
}
catch (Interruptedioexception x) {
thread.currentthread (). Interrupt ( );
}
catch (IOException x) {
trouble = true;
}
}
So let's look at the write method for the char array.
private void Write (char buf[]) {
try {
synchronized (this) {
ensureopen ();
Textout.write (BUF);
Textout.flushbuffer ();
Charout.flushbuffer ();
if (AutoFlush) {//We can see that he is writing each character to the output stream of the console. for
(int i = 0; i < buf.length i++)
if (buf[i] = = ' \ n ')
Out.flush ()
;
}}} catch (Interruptedioexception x) {
thread.currentthread (). interrupt ();
}
catch (IOException x) {
trouble = true;
}
}
In fact, this is the second time encountered this problem, but not very clear before, this lane clearly recorded, but also for everyone to refer to