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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:00:07+00:00 2026-05-22T00:00:07+00:00

Can someone tell me what’s wrong with this Java code? This array is :

  • 0

Can someone tell me what’s wrong with this Java code?
This array is : static String [][] data = new String[6][2]; But in this case, data[0][1]="abcd" and data[1][1]="efgh", the remaining data[2-5][1] should be null. I am just trying to print out the non-null ones. At (j=2,k=3), the code doesn’t get executed after that. For eg, the “I am here3” doesn’t get printed.

int k=1;  
System.out.println("data[2][0]="+data[2][0]);  

for(int j=0; j<data.length; j++,k++) {
    System.out.println("j="+j+" k="+k);

    if (!(data[j][0].equals("null"))) {
        System.out.println("I am here2");
        sbissues = sbissues.append("\n");
        sbissues = sbissues.append(k);
        sbissues = sbissues.append(".  ");
        sbissues = sbissues.append(data[j][1]);
    }

    System.out.println("sbissues="+sbissues.toString());
    System.out.println("I am here1");
}
System.out.println("I am here3");

The output looks like:

data[2][0]=null  
j=0 k=1  
I am here2  
sbissues=  
1.  abcd  
I am here1  
j=1 k=2  
I am here2  
sbissues=  
1.  abcd  
2.  efgh  
I am here1  
j=2 k=3  

The problem is that i never reach the “I am here3”.
Thanks guys for the answers, they are all correct (to use !=null instead of .equals). I guess i can’t vote for all of you, i’m just allowed to vote once.

  • 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-22T00:00:08+00:00Added an answer on May 22, 2026 at 12:00 am

    My guess is you don’t want it printing anything when it’s null.

    Use this for your if statement instead:

    if (data[j][0] != null) {
    

    In java complex variables are references to objects. You can have two variables pointing to the same object. When a variable is pointing to nothing then it’s null. You cannot dereference a null variable, that’s when you get a NullPointerException.

    The primitive data types like int, long, byte, etc. behave differently. Every time you assign you’re making a copy of the data. They cannot be null.

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

Sidebar

Related Questions

Can someone tell me if this is a bug in the SDK/IDE: Any custom
Can someone tell me why the following code intermittently throws an exception ? I
Can someone tell me why this doesnt work. When I enter the loop it
Can someone tell me how to create tabs in the title bar area of
can someone tell me what the difference is between [(id)Object class] and object_getClassName(id Object)
Can someone tell my when to use Overlay or when to use ItemizedOverlay class!
Can someone tell me in plan and simple terms what some of the more
Can someone tell me how do I achieve the UIActionSheet like behavior? I have
Can someone tell me, how I can access all contacts relating to a specific
Can someone tell me how I can scale an UIButton on touch? The button

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.