I have an int array which has no elements and I’m trying to check whether it’s empty.
For example, why is the condition of the if-statement in the code below never true?
int[] k = new int[3];
if (k == null) {
System.out.println(k.length);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
There’s a key difference between a
nullarray and an empty array. This is a test fornull.“Empty” here has no official meaning. I’m choosing to define empty as having 0 elements:
An alternative definition of “empty” is if all the elements are
null:or