
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compare Two Java Int Arrays
To compare two Java short arrays, use the Arrays.equals() method.
Let us first declare and initialize some int arrays.
int[] arr1 = new int[] { 33, 66, 12, 56, 99 }; int[] arr2 = new int[] { 33, 66, 12, 56, 99 }; int[] arr3 = new int[] { 33, 66, 15, 56, 90 };
Now let us compare any two of the above arrays.
Arrays.equals(arr1, arr2));
In the same way, work it for other arrays and compare them
Example
import java.util.*; public class Demo { public static void main(String[] args) { int[] arr1 = new int[] { 33, 66, 12, 56, 99 }; int[] arr2 = new int[] { 33, 66, 12, 56, 99 }; int[] arr3 = new int[] { 33, 66, 15, 56, 90 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr2, arr3)); System.out.println(Arrays.equals(arr3, arr1)); } }
Output
true false false
Advertisements