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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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: 859

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: 6109
    
    6

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: 1763
    
    7

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://aspose.com/file-tools
 
subject: print vs println using split method