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 String.split() ignores null fields Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String.split() ignores null fields" Watch "String.split() ignores null fields" New topic
Author

String.split() ignores null fields

Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
Please compile the following code and you'll see what I mean.

The API doesn't list an option to include null fields. This probably revolves around the philosophical discussion of the meaning of the "" string and a null string.
Practically speaking, is there way of making Java respect my nulls, even if they don't exist?
Can I split my string into {"this","is","a","simple","string","",""}?
Not even sure if this makes sense.

awk has no such hangups and works well. But for my present purposes I was thinking of engaging Java.

Thanks,
Sashi>
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16680
    
  19

This is specifically mentioned in the JavaDoc...

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

I'll let you read it on your own... but regarding your question, you want this.



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
Did I say that the API didn't mention what I'm looking for?
Spoken in haste.

Thanks, Henry!
Sashi
 
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: String.split() ignores null fields
 
Similar Threads
about String.split execution
query with escape characters
"\d" vs "\\d" while tokenizing
for loop error
split() method problem