Take the 2-minute tour ×  I came across this program and its not
behaving in expected way.  public class StringTest       public
static void main(String[] args)            String s = "Hello
world";  If we think it should print Hello world but it prints
nothing. What is going on? Any ideas? Thanks in advance.
share|improve this question You forgot to flush(). –  Jonathon
Mar 4 '11 at 21:01 add comment  1 Answer  up vote 11 down vote
accepted  You want: System.out.print(s.charAt(i));  As per the
API of write:  Note that the byte is written as given; to write
a character that will be translated according to the platform's
default character encoding, use the print(char) or println(char)
methods.  As noted in a comment to your question, if you really
wish to use write() you need to flush().  The reason why
write(int) doesn't print anything is because it only flushes the
stream on \n and when autoFlush is true.  public void write(int
b) {     try {         synchronized (this) {         if ((b ==
'\n') && autoFlush