Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 763449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:33:44+00:00 2026-05-14T16:33:44+00:00

I am trying to split a string into 29 tokens….. stringtokenizer won’t return null

  • 0

I am trying to split a string into 29 tokens….. stringtokenizer won’t return null tokens. I tried string.split, but I believe I am doing something wrong:

String [] strings = line.split(",", 29);

sample inputs:

10150,15:58,23:58,16:00,00:00,15:55,23:55,15:58,00:01,16:03,23:58,,,,,16:00,23:22,15:54,00:03,15:59,23:56,16:05,23:59,15:55,00:01,,,,
10155,,,,,,,,,,,07:30,13:27,07:25,13:45,,,,,,,,,,,07:13,14:37,08:01,15:23
10160,10:00,16:02,09:55,16:03,10:06,15:58,09:48,16:07,09:55,16:00,,,,,09:49,15:38,10:02,16:04,10:00,16:00,09:58,16:01,09:57,15:58,,,,
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:33:45+00:00Added an answer on May 14, 2026 at 4:33 pm

    If you want the trailing empty strings to be kept, but you don’t want to give a magic number for maximum, use a negative limit:

    line.split(",", -1)
    

    If line.equals("a,,c"), then line.split(",", -1)[1].isEmpty(); it’s not null. This is because when "," is the delimiter, then ",," has an empty string between the two delimiters, not null.


    Example:

    Using the explanation above, consider the following example: ",,"

    Although you might expect ",", null, and ",".

    The actual result is ",", "" and ","


    If you want null instead of empty strings in the array returned by split, then you’d have to manually scan the array and replace them with null. I’m not sure why s == null is better than s.isEmpty(), though.

    See also

    • Java String.indexOf and empty strings
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to split a string into a int list for further processing. But
I'm trying to split a string into tokens (via regular expressions) in the following
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I'm trying to find a Delphi function that will split an input string into
I'm trying to split a string on its punctuation, but the string may contain
I'm trying to split a string into sentences (delimited by sentence delimiters). The code
I'm trying to split up a string into two parts using regex. The string
I'm trying to use RegEx to split a string into several objects. Each record
I am trying to split a string into an array. This is the code
I am trying to split a string into an array of word pairs in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.