• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String.split() ignores null fields

 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21005
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did I say that the API didn't mention what I'm looking for?
Spoken in haste.

Thanks, Henry!
Sashi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic