JspWriter.write() and JspWriter.print()

I am debugging someone else's code.

What I don't get is why JspWriter.write() and JspWriter.print() were used interchangeably in that servlet.

Here is code snippet (shortened for brevity)

out.write("\r\n<div id=\"collapse_searchbar\" class=.....
out.write("\r\n            \t\t\t");
out.write("  <span class=\"fa fa-caret-down\"></span> \r\n.....

Open in new window

I know in general what is difference between those two methods but what's difference between JspWriter.write() and JspWriter.print() in this particular case, i.e. why using both of them at the same time?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Margaret GreenCommented:
The write() methods are inherited from the Writer super class. The write() methods can take int, char[], or String types. The print() methods of JspWriter are overloaded for many other types, such as boolean. In the example, the type of the list get()  will invoke the corresponding overloaded pint() method for that type.

It could be this code evolved over time, hence the differences.
KPaxAuthor Commented:
It could be this code evolved over time, hence the differences.

I don't know what to think about it - there are literally hundreds of code lines like that: few out.write then out.print(searchOptionList.get(0)); then all over again, for hundred lines, in all classes that deal with JSP. Almost all of the HTML, JSP & JavaScript are generated within servlets using JspWriter.write() and JspWriter.print().
KPaxAuthor Commented:
I found an answer on different but similar question. Answer is:

Are you looking at the .java files generated by a servlet engine? out.write and out.print are slightly different.  out.print does a bit more for you, and therefore might be slightly less efficient.  Hence, when the servlet engine chooses to use out.write, they are doing so when it seems as if it will be sufficient, else it chooses out.print.

At this point you would have to look at the source code of tomcat itself, or whatever servlet engine you are using to get a more definitive answer.

If you were working with the original .jsp files, I would expect your question to be quite different.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KPaxAuthor Commented:
This is correct answer, I found it as an answer to one of mine different but similar question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.