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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:31:00+00:00 2026-06-02T19:31:00+00:00

String a[]=null; if(a[0]!=null) { System.err.println(dd-1); } if(a!=null) { System.err.println(dd-2); } } In first if

  • 0
String a[]=null;
    if(a[0]!=null)
    {
        System.err.println("dd-1");
    }

    if(a!=null)
        {
        System.err.println("dd-2");
        }
    }

In first if condtion its throwing null pointer exception, but in second if condition its not throwing null pointer exception? can anyone please explain me the same? is there is any concept behind this on Heap memory allocation.

also i got to know the problem becauese of Missing memory allocation,String a[]=new String.[10]; please expalain the concept?

  • 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-02T19:31:01+00:00Added an answer on June 2, 2026 at 7:31 pm

    In the first if condition you are trying to access the first element in the array, even thought there is no allocation done for it.

    In second condition you are just testing the reference.

    (Think of it as C pointers, char *str = NULL does not allocated any thing except a pointer pointing to NULL)

    String a[]=null;
    

    No memory is allocated for the array only reference is created.

    String a[] = new String[1]
    

    Memory to hold one String object is created on the Heap and a points to the allocated string object.

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

Sidebar

Related Questions

String a []= {null,null,null,null,null}; //add array to arraylist ArrayList<Object> choice = new ArrayList<Object>(Arrays.asList(a)); System.out.println(choice.size());
First off, this is NOT a duplicate of: Turn a C string with NULL
private: System::Void btn_entrar_Click(System::Object^ sender, System::EventArgs^ e) { string btn_texto = txt_login->Text->ToString(); MessageBox(NULL, Hello!, btn_texto.c_str(),
private static synchronized String[][] map2data(Map<String, Object> map) { if (map != null) { String[][]
A there any g++ options which can detect improper initialization of std::string with NULL
Is it possible to convert null to string with php? For instance, $string =
final String message[] = {,,}; try{ String UID = null, UBAL = null; DateFormat
In C# you can do the following: string y = null; string x =
With vim how do I to turn this: t.string :crypted_password :null => false t.string
why is doing the following so bad? String val = null; String someOtherValue =

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.