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

  • Home
  • SEARCH
  • 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 6201485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:33:48+00:00 2026-05-24T04:33:48+00:00

Is it possible for split to return a null String[] ? I am curious

  • 0

Is it possible for split to return a null String[]? I am curious as I want to try to be as defensive as possible in my code without having unnecessary checks. The code is as follows:

String[] parts = myString.split("\\w");  

do I need to perform a null check before I use parts post splitting?

  • 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-24T04:33:49+00:00Added an answer on May 24, 2026 at 4:33 am

    It never returns null. You should always check the javadoc of the method if you are not sure. For example String#split(String) says

    This method works as if by invoking the two-argument split method

    …and String#split(String,int) says:

    If the expression does not match any part of the input then the resulting array has just one element, namely this string.

    From Javadoc you can also find out what kind of exceptions can happen and more importantly why were those exceptions thrown. Also one very important thing to check is if the classes are thread safe or not.

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

Sidebar

Related Questions

I want to split a string suppressing all null fields Command: ,1,2,,3,4,,.split(',') Result: [,
Possible Duplicate: Split string in SQL I have seen a couple of questions related
Possible Duplicate: Split string to equal length substrings in Java Given the following utility
I have this code void split(vector<float> &fvec, string str) { int place = 0;
Possible Duplicate: string split in java I have this Key - Value , and
Possible Duplicate: Why does Enumerable.All return true for an empty sequence? Code: var line
Is it possible to split the information in a .csproj across more than one
Is it possible to split large ASP.NET-pages into pieces? JSP has the jsp:include directive.
Is it possible to split a tag at lower to upper case boundaries i.e.
is it possible to split 2 images vertically and when resizing the browser, it

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.