- 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
What does the method equals(int[] a1, int[] a2) do in java?
The equals(int[] a, int[] a2) method of java.util.Arrays returns true if the two specified arrays of integers are equal to one another. Two arrays are equal if they contain the same elements in the same order. Two array references are considered equal if both are null.
Example
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { int[] arr1 = new int[] { 10, 12, 5, 6 }; int[] arr2 = new int[] { 10, 12, 5, 6 }; int[] arr3 = new int[] { 10, 5, 6, 12 }; boolean retval = Arrays.equals(arr1, arr2); System.out.println("arr1 and arr2 equal: " + retval); boolean retval2 = Arrays.equals(arr2, arr3); System.out.println("arr2 and arr3 equal: " + retval2); } }
Output
arr1 and arr2 equal: true arr2 and arr3 equal: false
Advertisements