- 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
How to compare arrays in Java
Following example uses equals method to check whether two arrays are or not.
Example
import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { int[] ary = {1,2,3,4,5,6}; int[] ary1 = {1,2,3,4,5,6}; int[] ary2 = {1,2,3,4}; System.out.println("Is array 1 equal to array 2?? " +Arrays.equals(ary, ary1)); System.out.println("Is array 1 equal to array 3?? " +Arrays.equals(ary, ary2)); } }
Output
The above code sample will produce the following result.
Is array 1 equal to array 2?? true Is array 1 equal to array 3?? false
- Related Articles
- How to compare two arrays in Java?
- How do we compare two arrays in Java?
- Compare Two Java int Arrays in Java
- Java Program to compare Two Java float Arrays
- Java Program to compare Two Java short Arrays
- Java Program to compare two Java char Arrays
- How to compare arrays in JavaScript?
- Compare Two Java long Arrays
- Compare Two Java double arrays
- Java Program to compare two Boolean Arrays
- Java Program to compare two Byte Arrays
- How to compare two arrays in C#?
- How to compare two arrays for equality in Perl?
- Compare two int arrays in a single line in Java
- Compare two short arrays in a single line in Java

Advertisements