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 8216887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:17:16+00:00 2026-06-07T12:17:16+00:00

Java Experts , Please look into the below split command code and let me

  • 0

Java Experts ,

Please look into the below split command code and let me know why last two nulls are not captured.

String test = "1,O1,,,,0.0000,0.0000,,";
String[] splittest = test.split(",");
System.out.println("length -"+splittest.length);
for (String string : splittest) {
    System.out.println("value"+string);
}

The result iam getting

length -7
value1
valueO1
value
value
value
value0.0000
value0.0000

surprisingly the length is 7 where as it should be 9 and also as you can see values after 0.0000 ie two last nulls are not coming . Lets say now if i change the string test
“1,O1,,,,0.0000,0.0000,0,0”

String test = "1,O1,,,,0.0000,0.0000,0,0";
String[] splittest = test.split(",");
System.out.println("length -"+splittest.length);
for (String string : splittest) {
    System.out.println("value"+string);
}

I am getting correctly

length -9
value1
valueO1
value
value
value
value0.0000
value0.0000
value0
value0

I don’t think iam doing wrong . Is it a bug ? JAVA Version – jdk1.6.0_31

  • 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-06-07T12:17:17+00:00Added an answer on June 7, 2026 at 12:17 pm

    It behaves as specified in the javadoc:

    This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

    If you want to keep the trailing blank strings, you can use the 2 argument split method with a negative limit:

    String[] splittest = test.split(",", -1);
    

    If the limit is non-positive then the pattern will be applied as many times as possible and the array can have any length.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

java experts can you please help me write detached queries as a part of
This might be a piece of cake for java experts. Please help me out:
I'm not a CS guru nor a Java expert, so please forgive me if
Hi I'm not particular good at Java so please bear with me. I'm trying
JAVA : is there a difference between the two references p && pp? PrintStream
Java noob question: Consider the following C array and initializer code: struct { int
I am developing a standalone application in Java using swing API. I need experts
Just to be sure, can experts confirm that java.util.concurrent.locks.Lock and Doug Lea's original Sync
From Java Malik textbook- determine if an number is divisible by 11.. Code Solution
Hello Experts can somebody please indentify the problem with this server why this is

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.