Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exact difference between out.write() and out.print()

In my servlet I gave both out.print and out.write. but both prints in the browser.

What is the exact difference between these two and when to use out.print and out.write ?

like image 554
Kumaran Palani Avatar asked Aug 20 '13 14:08

Kumaran Palani


People also ask

What is the difference between system out print () and system out Println ()?

The only difference between println and print method is that println throws the cursor to the next line after printing the desired result whereas print method keeps the cursor on the same line.

What is out write ()?

write() method only writes characters to stream(or console) but does not print, while print() method writes and print it on stream (or console). System. out. write(97); System.

What is the difference between write and print in Java?

print() formats the output, while write() just prints the characters it is given. print() handles many argument types, converting them into printable strings of characters with String. valueOf(), while write() just handles single characters, arrays of characters, and strings.

Is PrintWriter faster than system out Println?

By using PrintWriter than using System. out. println is preferred when we have to print a lot of items as PrintWriter is faster than the other to print data to the console.


1 Answers

The basic difference is that out.write() explodes if you pass it a null:

String s = null;
out.print(s); // outputs the text "null"
out.write(s); // NullPointerException
like image 129
Bohemian Avatar answered Oct 15 '22 00:10

Bohemian