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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:31:38+00:00 2026-05-28T05:31:38+00:00

Sometimes, or well, pretty often i need to see if a String is null

  • 0

Sometimes, or well, pretty often i need to see if a String is null or isn’t, so i use a conditional like this:

if(str != null) {
}

It worked fine until this day, now even strings that are null pass for some reason which I don’t get. Does anyone that knows an explanation? or a solution?

Edit:
OK, so for some reason the string doesn’t seem to be null, which is very odd since i never defined what it was, only denfined that it existed. So instead the string was a string of the word “null”. Which i have totally no idea why it would be? When i do following:

String str;

then it’s automatically null, right? And either way if it’s not why would it become the string “null”?

  • 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-28T05:31:39+00:00Added an answer on May 28, 2026 at 5:31 am

    I would check for length as well after checking for null:

    if(stringVar == null || stringVar.length() == 0) { /* DO STUFF */ }
    

    To make life easier you can make a extension method:

    public static boolean notEmpty(String s) 
    { 
    return (s != null && s.length() > 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've this little script which does it's job pretty well but sometimes it tends
Sometimes I need to quickly extract some arbitrary data from XML files to put
Sometimes we deploy applications behind customer firewall and we need read only access to
Well.. it's pretty much that, I seem to be getting a Illegal Seek error
I'm having some problems with ActiveRecord. Well everything works fine, but it's working sometimes.
Sometimes when reading others' C# code I see a method that will accept multiple
My current .htaccess looks like this: RewriteEngine On # RewriteCond %{REQUEST_URI} !^/_project RewriteCond %{REQUEST_FILENAME}
Quite often, Git and Ruby on Rails looks like magic... such as in the
Sometimes it's nice to open an interpreter, type out some code and see if
This is a pretty strange issue so bear with me. I have a stored

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.