in Education by
So I'm basically finished with a program, and at the end of it I'm printing Strings from an array to a file. The array may contain null values, so I'm checking for null before I print, but I keep ending up with 1 null at the very end of the file... Here's the code I'm using to check for null for(int i=0;i<array2.length;i++) { if(array2[i] != null) out.println(array2[i]); } I know that the array contains multiple instances of null, but only 1 is being printed. I tried using the debugger and when array2[i] == null, it still entered the conditional statement... So I added a println statement to help me see what's going on. It now looks like this: for(int i=0;i<array2.length;i++) { if(array2[i] != null) { System.out.println("Adding " + array2[i]); out.println(array2[i]); } Just after printing all the String values to the console, it prints "Adding null" so I know it's happening here in this if statement. Why is this happening??? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The debugger is not always clear as to whether it has entered an if condition or not. I don't believe this code is entering the if condition which it might appear it is and your null is probably coming from another line of code. You could write the code as for(ElementType e: array2.length) if(e != null) out.println("[" + e+ ']'); // extra text for debugging. // I suspect your `null` will still be on a line of its own

Related questions

0 votes
    This question's answers are a community effort. Edit existing answers to improve this post. It is not ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am simply trying to read each character from a file and print them in the screen. For testing, I tried to print ... ("count.txt"); } void CountLetters(string filename) { cout...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I am simply trying to read each character from a file and print them in the screen. For testing, I tried to print ... ("count.txt"); } void CountLetters(string filename) { cout...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have developed a website that queries NASA's image API. The website works fine on my desktop browser. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I want to display among other things a Label containing an Image , the image in this Label is a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Hello I am quite new to pygame and I am trying to make an intro for a game where the user hovers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I want to make use of tabs layout within tabs layout. I am using Material Design lite which has ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Can anyone help me, Im trying to make a simple app where you touch the screen and 4 images are ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Can anyone help me, Im trying to make a simple app where you touch the screen and 4 images are ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    The ******* or newbie in the field of hacking who don't have many skills about coding and in-depth working ... Cyber Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 5, 2021 in Education by JackTerrance
0 votes
    “Simple Language” what do you understand by the term in effective communication? Firstly read the question !!! Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Unix is very simple it just needs a genius to understand its simplicity Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    I have a Docker container with MariaDB installed. I am not using any volumes. [vagrant@devops ~]$ sudo ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    DROP TYPE Position; CREATE OR REPLACE TYPE Position AS OBJECT (longitude NUMBER(11,7), lattitude NUMBER(11, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
...