Compare the elements of an array (Java)

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

Compare the elements of an array (Java)
[Swift] How to get the number of elements in an array (super basic)
About an instance of java
Summarize the additional elements of the Optional class in Java 9
[Note] Java Output of the sum of odd and even elements
Java beginners briefly summarized the behavior of Array and ArrayList
[Java] Try editing the elements of the Json string using the library
How to add elements without specifying the length of the array
Be sure to compare the result of Java compareTo with 0
Generate Stream from an array of primitive types in Java
Java learning memo (creating an array)
[Java version] The story of serialization
[Java] Declare and initialize an array
The origin of Java lambda expressions
A program (Java) that outputs the sum of odd and even numbers in an array
[Java] array
Java array
Java array
java (array)
[Swift5] How to get an array and the complement of arrays
Java array
The story of toString () starting with passing an array to System.out.println
Java array
Cast an array of Strings to a List of Integers in Java
12 of Array
java array
[Java] Array
How to get the length of an audio file in java
Let's summarize the Java 8 grammar from the perspective of an iOS engineer
Extract elements of array / extract in reverse order-java
Get the result of POST in Java
[Java] Get the day of the specific day of the week
Memo: [Java] Check the contents of the directory
Organized memo in the head (Java --Array)
[day: 5] I summarized the basics of Java
What are the updated features of java 13
Easily measure the size of Java Objects
Convert an array of strings to numbers
Looking back on the basics of Java
[Ruby] Get unique elements from an array
[Java beginner] About initialization of multidimensional array
Output of the book "Introduction to Java"
The story of writing Java in Emacs
[Java] Check the number of occurrences of characters
Sort an array of Ruby homebrew classes
[Java] [Spring] Test the behavior of the logger
[Swift] Summary of how to remove elements from an array (personal note)
How to convert an array of Strings to an array of objects with the Stream API
Get the type of an array element to determine if it is an array
Java engineers now compare to learn the basic grammar of Ruby Part 1 (Basic, Variables)
[Java] How to convert one element of a String type array to an Int type
The story of low-level string comparison in Java
[Java] Handling of JavaBeans in the method chain
JAVA: jar, aar, view the contents of the file
java array variable
[Ruby] Calculation by extracting elements from an array
The story of making ordinary Othello in Java
[Android] [Java] Manage the state of CheckBox of ListView
About the description order of Java system properties
About the idea of anonymous classes in Java
The order of Java method modifiers is fixed