This was discovered when writing junit tests.
1 ImportJava.io.ByteArrayOutputStream;2 ImportJava.io.PrintStream;3 4 Public classTest {5 Public Static voidMain (string[] args) {6PrintStream out=System.out;7Bytearrayoutputstream outcontent =NewBytearrayoutputstream ();8System.setout (NewPrintStream (outcontent));9System.out.println ("Hello");Ten System.setout (out); OneSystem.out.println (Outcontent.tostring (). Equals ("hello\n")); A Outcontent.reset (); -System.setout (NewPrintStream (outcontent)); -System.out.print ("hello\n"); the System.setout (out); -System.out.println (Outcontent.tostring (). Equals ("hello\n")); - } -}
The result of the above program output is false true. This means that the characters that are output by System.out.println () and System.out.print ("\ n") are still different. You need to be aware of this if you want to redirect output to Str for testing equality.
About the difference between System.out.println () and System.out.print ("\ n")