Comparing NULL values in Java
I have a code that compares data but that data contains null values not blank spaces ("") they may/may not be same i guess but I tried comparing repetitive NULL values like
for(int i=0;i<length;i++)
I could have used .contains but that wont work because it is in the loop.
None of the method makes it print the output as No Data I have tried using try catch as well because in order to make sure if theres any error found and was correct at the same time isEmpty() and .equals(null) were somewhere or the other throwing the exception as NULL but even after removing and simply using ==Null realizing the fact that data is itself null and comparing like null.equals wont work but in case of == I found that the error exception got changed to value as 1 thereafter the same error and I wasnt able to recognize this.
Its the sample here which I am showing I cant post the exact but the above makes quite clear. Is there any other way I could treat these NULL values.
Note : I dont want to use a loop to iterate data as well and each time comparing
NULLvalues because already theres an outer loop for large set of values dont go by the sample code.
java algorithm programming-languages
add a comment |
I have a code that compares data but that data contains null values not blank spaces ("") they may/may not be same i guess but I tried comparing repetitive NULL values like
for(int i=0;i<length;i++)
I could have used .contains but that wont work because it is in the loop.
None of the method makes it print the output as No Data I have tried using try catch as well because in order to make sure if theres any error found and was correct at the same time isEmpty() and .equals(null) were somewhere or the other throwing the exception as NULL but even after removing and simply using ==Null realizing the fact that data is itself null and comparing like null.equals wont work but in case of == I found that the error exception got changed to value as 1 thereafter the same error and I wasnt able to recognize this.
Its the sample here which I am showing I cant post the exact but the above makes quite clear. Is there any other way I could treat these NULL values.
Note : I dont want to use a loop to iterate data as well and each time comparing
NULLvalues because already theres an outer loop for large set of values dont go by the sample code.
java algorithm programming-languages
1
View > Connections. If that doesn't work, Windows > Restore Windows to Factory Settings.
– thatjeffsmith
Nov 13 '18 at 20:24
add a comment |
I have a code that compares data but that data contains null values not blank spaces ("") they may/may not be same i guess but I tried comparing repetitive NULL values like
for(int i=0;i<length;i++)
I could have used .contains but that wont work because it is in the loop.
None of the method makes it print the output as No Data I have tried using try catch as well because in order to make sure if theres any error found and was correct at the same time isEmpty() and .equals(null) were somewhere or the other throwing the exception as NULL but even after removing and simply using ==Null realizing the fact that data is itself null and comparing like null.equals wont work but in case of == I found that the error exception got changed to value as 1 thereafter the same error and I wasnt able to recognize this.
Its the sample here which I am showing I cant post the exact but the above makes quite clear. Is there any other way I could treat these NULL values.
Note : I dont want to use a loop to iterate data as well and each time comparing
NULLvalues because already theres an outer loop for large set of values dont go by the sample code.
java algorithm programming-languages
I have a code that compares data but that data contains null values not blank spaces ("") they may/may not be same i guess but I tried comparing repetitive NULL values like
for(int i=0;i<length;i++)
I could have used .contains but that wont work because it is in the loop.
None of the method makes it print the output as No Data I have tried using try catch as well because in order to make sure if theres any error found and was correct at the same time isEmpty() and .equals(null) were somewhere or the other throwing the exception as NULL but even after removing and simply using ==Null realizing the fact that data is itself null and comparing like null.equals wont work but in case of == I found that the error exception got changed to value as 1 thereafter the same error and I wasnt able to recognize this.
Its the sample here which I am showing I cant post the exact but the above makes quite clear. Is there any other way I could treat these NULL values.
Note : I dont want to use a loop to iterate data as well and each time comparing
NULLvalues because already theres an outer loop for large set of values dont go by the sample code.
java algorithm programming-languages
java algorithm programming-languages
edited Dec 10 '18 at 21:01
Himanshu Ahuja
asked Nov 13 '18 at 20:01
Himanshu AhujaHimanshu Ahuja
7342217
7342217
1
View > Connections. If that doesn't work, Windows > Restore Windows to Factory Settings.
– thatjeffsmith
Nov 13 '18 at 20:24
add a comment |
1
View > Connections. If that doesn't work, Windows > Restore Windows to Factory Settings.
– thatjeffsmith
Nov 13 '18 at 20:24
1
1
View > Connections. If that doesn't work, Windows > Restore Windows to Factory Settings.
– thatjeffsmith
Nov 13 '18 at 20:24
View > Connections. If that doesn't work, Windows > Restore Windows to Factory Settings.
– thatjeffsmith
Nov 13 '18 at 20:24
add a comment |
2 Answers
2
active
oldest
votes
Restoring windows to factory settings will restore windows (as its name suggests); it won't spoil anything.
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the[>marker.
– another-dave
Jan 3 at 11:52
add a comment |
In this
String data=sample_data.getData();// contains about 1000 null rows
if(data.equals(null) || data.equals("") || data== null
you are apparently concerned that data may be null.
If indeed it is null, then the very first clause in your if statement will throw a null pointer exception... because you can't call the equals method on a null reference.
You want
if (data == null || data.isEmpty())
and that covers all the cases of nothing, except possibly the case where data is "some number of space characters", but I'll leave that for you.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288631%2fcomparing-null-values-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Restoring windows to factory settings will restore windows (as its name suggests); it won't spoil anything.
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the[>marker.
– another-dave
Jan 3 at 11:52
add a comment |
Restoring windows to factory settings will restore windows (as its name suggests); it won't spoil anything.
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the[>marker.
– another-dave
Jan 3 at 11:52
add a comment |
Restoring windows to factory settings will restore windows (as its name suggests); it won't spoil anything.
Restoring windows to factory settings will restore windows (as its name suggests); it won't spoil anything.
answered Nov 13 '18 at 20:25
LittlefootLittlefoot
23k71533
23k71533
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the[>marker.
– another-dave
Jan 3 at 11:52
add a comment |
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the[>marker.
– another-dave
Jan 3 at 11:52
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
yeah at first even i thought it wont affect because it is the view of the window but my datab
– Himanshu Ahuja
Nov 14 '18 at 7:39
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
Hmm? The question is about comparing null values in Java.
– another-dave
Jan 3 at 2:40
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@another-dave, at the time I posted my message, it was valid. Have a look at history of the question's editing - you'll see that revision #2 actually was what I was answering to (as well as what thatjeffsmith commented under the question). I don't know why the OP changed the question in such a drastic way, instead of opening a new one.
– Littlefoot
Jan 3 at 7:45
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the
[> marker.– another-dave
Jan 3 at 11:52
@Littlefoot - aha. I had checked, but not carefully enough; "version 1" of the question was not expanded until I noticed and clicked on the
[> marker.– another-dave
Jan 3 at 11:52
add a comment |
In this
String data=sample_data.getData();// contains about 1000 null rows
if(data.equals(null) || data.equals("") || data== null
you are apparently concerned that data may be null.
If indeed it is null, then the very first clause in your if statement will throw a null pointer exception... because you can't call the equals method on a null reference.
You want
if (data == null || data.isEmpty())
and that covers all the cases of nothing, except possibly the case where data is "some number of space characters", but I'll leave that for you.
add a comment |
In this
String data=sample_data.getData();// contains about 1000 null rows
if(data.equals(null) || data.equals("") || data== null
you are apparently concerned that data may be null.
If indeed it is null, then the very first clause in your if statement will throw a null pointer exception... because you can't call the equals method on a null reference.
You want
if (data == null || data.isEmpty())
and that covers all the cases of nothing, except possibly the case where data is "some number of space characters", but I'll leave that for you.
add a comment |
In this
String data=sample_data.getData();// contains about 1000 null rows
if(data.equals(null) || data.equals("") || data== null
you are apparently concerned that data may be null.
If indeed it is null, then the very first clause in your if statement will throw a null pointer exception... because you can't call the equals method on a null reference.
You want
if (data == null || data.isEmpty())
and that covers all the cases of nothing, except possibly the case where data is "some number of space characters", but I'll leave that for you.
In this
String data=sample_data.getData();// contains about 1000 null rows
if(data.equals(null) || data.equals("") || data== null
you are apparently concerned that data may be null.
If indeed it is null, then the very first clause in your if statement will throw a null pointer exception... because you can't call the equals method on a null reference.
You want
if (data == null || data.isEmpty())
and that covers all the cases of nothing, except possibly the case where data is "some number of space characters", but I'll leave that for you.
edited Jan 3 at 2:44
answered Jan 3 at 2:37
another-daveanother-dave
80316
80316
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288631%2fcomparing-null-values-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
View > Connections. If that doesn't work, Windows > Restore Windows to Factory Settings.
– thatjeffsmith
Nov 13 '18 at 20:24