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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:41:32+00:00 2026-05-31T06:41:32+00:00

There is a function get() that return a value if it is there in

  • 0

There is a function get() that return a value if it is there in ArrayDeque otherwise returns null i.e x can be some value or null. If get() returns x then function B() should perform some computations otherwise should not do anything.

T get()
{
    //compute x
    return x;
}

void B()
{
     int z;
     if(y.get()!=null)
     {
          z=y.get(); // gives null pointer exception
          .....
     }
}

The problem is that y.get() already returns the value which is not assigned to any variable, thus gives null pointer exception. If i use something like if((z=y.get()) != 0) it gives exception in cases when x is null. How can i achieve this functionality?

  • 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-31T06:41:33+00:00Added an answer on May 31, 2026 at 6:41 am

    I suspect this is an ArrayDeque<Integer>, right?

    When you have:

    int z = y.get();
    

    That’s like saying:

    int z = ((Integer) y.get()).intValue();
    

    Just use:

    Integer z = y.get();
    

    instead. Then you can test whether z is null. On the other hand, if y.get() has already returned a non-null value, I’m surprised if it’s then returning a null value – you’d expect it to return the same thing twice, right? Are there other threads involved?

    Additionally, it’s not clear what you mean by this:

    The problem is that y.get() already returns the value which is not assigned to any variable, thus gives null pointer exception.

    I don’t see where the “thus” in here… it’s fine to call a method and not store the return value in a variable. If that’s throwing a NullPointerException, it would really suggest that y is null. Of course, all of this would be easier to diagnose if you would post a short but complete program demonstrating the problem.

    As an aside, it’s not clear why you’re calling y.get() twice in the first place. I would restructure the code to:

    void B()
    {
         Integer z = y.get();
         if (z != null)
         {
             // Use z
         }
    }
    

    Do you really want to call it twice?

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

Sidebar

Related Questions

If I have a function that returns an object, but this return value is
Is there a way to set up a function that will get the user
There's a function in PHP where you can get a list of the user
lint produces some warning like: foo.c XXX Warning 534: Ignoring return value of function
It would appear that there is a size limit on the return value of
A class implements a public function that calculates some value. During the calculation the
Is there a function for SAP DB to get the length of a string
I want to consume a web service using jquery's get function. There is no
I'm wondering if there is a quick and easy function to clean get variables
Before debugging the late-hour-out-of-bound-recursive-function: is there a command to get subdirs? giveMeSubDirs(downToPath) ? //

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.