Hi the below is my program , could you please tell me why the first condition is ot being executed ??
package com;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String args[]) {
List<String> values = null;
String Id = "1234";
if (values != null && Id != null && values.size() > 1
&& !values.contains(Id)) {
// This is never executed
System.out.println("Throw Exception");
} else {
// This is always called
System.out.println("Fine");
}
}
}
You always end up in the
elsecase, becausevaluesisnulland yourifcondition needsvalues != null.Maybe you should have a look at basic Boolean Algebra to understand why the
ifcondition cannot betruein your case.