how do we test for null values in single dimensional string array?
testing for null in a single dimensional array
Collapse
X
-
Originally posted by veremuehow do we test for null values in single dimensional string array?
* http://java.sun.com/docs/books/tutor...bolts/for.html -
Originally posted by veremuehow do we test for null values in single dimensional string array?
Only String data type accepts null value. Integer or character does not accept null values. To test null value in string data type just use == operator in if condition like below,
if(str[3] == null)
{
}
Thanks,Comment
-
Originally posted by rsrinivasanHi,
Only String data type accepts null value. Integer or character does not accept null values. To test null value in string data type just use == operator in if condition like below,
if(str[3] == null)
{
}
Thanks,
* http://java.sun.com/docs/books/tutor...datatypes.htmlComment
-
Originally posted by rsrinivasanHi,
Only String data type accepts null value. Integer or character does not accept null values.
null is accepted as a valid value:[code=java]
class Person { ... }
...
Person[] persons= new Person[42];
...
// this is accepted:
persons[7]= null;[/code]
kind regards,
JosComment
-
Originally posted by JosAH... and who is the slowest old sod again? ;-)
kind regards,
Jos
; )
...Comment
-
Originally posted by rsrinivasanHi,
Only String data type accepts null value. Integer or character does not accept null values. To test null value in string data type just use == operator in if condition like below,
if(str[3] == null)
{
}
Thanks,
[CODE=java]Integer number = null;[/CODE]
compiles fine.
int and char (primitives) are the ones that cannot have a value of null.Comment
-
Originally posted by r035198xYack, I was so beaten there!
perfectly written article was just one single short minute but between my gem of
a reply and your short reply were five whole minutes! ;-)
kind regards,
JosComment
-
just declare any reference type and make it reference null.
TypeDeclared typevar = null;
then test for equivalence to these typevar like:
if ( x == typevar){ //statement here}
that's all.
String is also a reference typeComment
Comment