- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to compare Two Java short Arrays
To compare two Java short arrays, use the Arrays.equals() method.
Let us first declare and initialize some short arrays.
short[] arr1 = new short[] { 20, 15, 35, 55, 69 }; short[] arr2 = new short[] { 20, 15, 35, 55, 69 }; short[] arr3 = new short[] { 22, 19, 30, 45, 78 };
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) { short[] arr1 = new short[] { 20, 15, 35, 55, 69 }; short[] arr2 = new short[] { 20, 15, 35, 55, 69 }; short[] arr3 = new short[] { 22, 19, 30, 45, 78 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr2, arr3)); System.out.println(Arrays.equals(arr1, arr3)); } }
Output
true false false
- Related Articles
- Java Program to compare two Java char Arrays
- Java Program to compare Two Java float Arrays
- Java Program to compare two Boolean Arrays
- Java Program to compare two Byte Arrays
- Compare two short arrays in a single line in Java
- Compare Two Java long Arrays
- Compare Two Java double arrays
- Compare Two Java int Arrays in Java
- How to compare two arrays in Java?
- Java Program to compare two sets
- Java Program to Compare Two Strings
- How do we compare two arrays in Java?
- Java Program to Concatenate Two Arrays
- Program to Compare two strings in Java
- Java Program to Compare two strings lexicographically

Advertisements