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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:29:03+00:00 2026-05-28T14:29:03+00:00

I am passing an accountid as input from an XML file as shown, which

  • 0

I am passing an accountid as input from an XML file as shown, which will be parsed later and will be used in our code:

<accountid>123456</accountid>
<user>pavan</user>

The issue is that if nothing is passed (null value in accoutnid) is passed as accountid, I could not able to handle that situation in Java code. I tried this but I was not successful:

if (acct != null||acct==""||acct.equals("")) 
{
    // the above is not working 
}

I was able to handle this successfully using the following approach:

if(!acct.isEmpty())
{
   // thisis working 
}

Can we rely on the String.isEmpty() method for checking the null condition of a String? Is this valid?

  • 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-28T14:29:04+00:00Added an answer on May 28, 2026 at 2:29 pm

    No, absolutely not – because if acct is null, it won’t even get to isEmpty… it will immediately throw a NullPointerException.

    Your test should be:

    if (acct != null && !acct.isEmpty())
    

    Note the use of && here, rather than your || in the previous code; also note how in your previous code, your conditions were wrong anyway – even with && you would only have entered the if body if acct was an empty string.

    Alternatively, using Guava:

    if (!Strings.isNullOrEmpty(acct))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Passing an undimensioned array to the VB6's Ubound function will cause an error, so
passing post data using cURL requires that the name of the input. However, I
Passing in an Expression to a Linq query behaves differently depending on syntax used,
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I'm used to passing around string like this in my C++ applications: void foo(const
I have an application where I can make calls, that will take anywhere from
I have a REST service that's reasonably complete and will be used with an
I'm having trouble parsing this xml file using jquery: <?xml version=1.0 encoding=utf-8?> <?mso-infoPathSolution name=urn:schemas-microsoft-com:office:infopath:BOT-Memos:-myXSD-2011-07-13T14-29-57
I am successfully passing a 64 bit number from a objC client to a
I have the following python code: row = conn.execute('''SELECT admin FROM account WHERE password

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.