File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes print vs println using split method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "print vs println using split method" Watch "print vs println using split method" New topic
Author

print vs println using split method

Oceana Wickramasinghe
Ranch Hand

Joined: Mar 02, 2011
Posts: 77
When using this code



i get the output :sddsfsdd

So its not returning empty strings.

But if i replace print with println

i get the output:

sd

dsf



sdd

Can someone tell me why println prints empty strings but why print doesnt?
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

println adds a newline after each token. print does not.

So what you are seeing with print is a concatenation of the tokens (including the empty ones "").

try:


WP
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 5783
    
    5

Oceana Wickramasinghe wrote:
So its not returning empty strings.


But it is.

Try this:


Then try it again with println() instead of print().

Then try both again without any of the "empty" lines.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1402

The println() method prints a String value followed by a line break character. What you're seeing are the line break characters, not the empty String values.

Edit: Dang, way too slow...


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: print vs println using split method
 
Similar Threads
Servlet Communication using java.net
array to list conversion
Doubt with Kathy sierra chapter 10
The "toString()" method.
Confusion with toString Method