String str ="Hello";if (str.isEmpty()) {// Code block for empty string} else {// Code block for non-empty string}
Check if an array is empty or not:
int[] numbers = {1,2,3};if (numbers.length==0) {// Code block for empty array} else {// Code block for non-empty array}
Check if a condition is true or false:
boolean flag =true;if (flag) {// Code block if flag is true} else {// Code block if flag is false}
Check if a reference is null or not:
String str =null;if (str ==null) {// Code block if str is null} else {// Code block if str is not null}
Check if two objects are equal or not:
String str1 ="Hello";String str2 ="World";if (str1.equals(str2)) {// Code block if str1 equals str2} else {// Code block if str1 does not equal str2}
Check if a condition is true, false, or unknown:
boolean condition =true;if (condition) {// Code block if condition is true} elseif (!condition) {// Code block if condition is false} else {// Code block if condition is unknown}
Check if a string contains a specific substring:
String str ="Hello, World!";if (str.contains("World")) {// Code block if str contains "World"} else {// Code block if str does not contain "World"}
Check if a number is divisible by another number:
int number =15;int divisor =3;if (number % divisor ==0) {// Code block if number is divisible by divisor} else {// Code block if number is not divisible by divisor}
Check if a number is within a specific range:
int number =20;int lowerBound =10;int upperBound =30;if (number >= lowerBound && number <= upperBound) {// Code block if number is within the range} else {// Code block if number is outside the range}
Check if a character is uppercase or lowercase:
char ch ='A';if (Character.isUpperCase(ch)) {// Code block if ch is uppercase} elseif (Character.isLowerCase(ch)) {// Code block if ch is lowercase} else {// Code block if ch is not a letter}
Check if an object is an instance of a specific class:
Object obj ="Hello";if (obj instanceof String) {// Code block if obj is an instance of String} else {// Code block if obj is not an instance of String}
Check if an array contains a specific element:
int[] numbers = {1,2,3,4,5};int target =3;boolean found =false;for (int num : numbers) {if (num == target) { found =true;break; }}if (found) {// Code block if target is found in the array} else {// Code block if target is not found in the array}
Check if a file exists:
importjava.io.File;File file =newFile("path/to/file.txt");if (file.exists()) {// Code block if file exists} else {// Code block if file does not exist}
Check if a condition is false:
boolean condition =false;if (!condition) {// Code block if condition is false} else {// Code block if condition is true}
Check if a string starts or ends with a specific substring:
String str ="Hello, World!";if (str.startsWith("Hello")) {// Code block if str starts with "Hello"} elseif (str.endsWith("World!")) {// Code block if str ends with "World!"} else {// Code block if str does not start with "Hello" and does not end with "World!"}
Check if a number is zero or non-zero:
int number =0;if (number ==0) {// Code block if number is zero} else {// Code block if number is non-zero}