Source code
ArrayTest.java
public class ArrayTest {
public static void main(String[] args) {
String[] array = {"AIUEO", "AIUEO", "Kakikukeko", null, null};
for (int i = 0; i < array.length-1; i++){
if (array[i] == array[i+1]) {
if (array[i] == null) {
System.out.println(array[i]+"When"+array[i+1]+"Are both NULL");
} else {
System.out.println(array[i]+"When"+array[i+1]+"Is the same");
}
} else {
if (array[i] == null || array[i+1] == null) {
System.out.println(array[i]+"When"+array[i+1]+"Is one null");
} else {
System.out.println(array[i]+"When"+array[i+1]+"Different");
}
}
}
}
}
Output result
Aiueo and Aiueo are the same
Aiueo Tokaki Kukeko is different
One of Kakikukeko and null is NULL
Both null and null are null
Recommended Posts