 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Java Program to compare two Java char Arrays
To compare two Java char arrays, use the Arrays.equals() method.
Let us first declare and initialize some char arrays.
char[] arr1 = new char[] { 'p', 'q', 'r' }; char[] arr2 = new char[] { 'p', 'r', 's' }; char[] arr3 = new char[] { 'p', 'q', 'r' }; 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.
The following is an example.
Example
import java.util.*; public class Demo {    public static void main(String []args) {       char[] arr1 = new char[] { 'p', 'q', 'r' };       char[] arr2 = new char[] { 'p', 'r', 's' };       char[] arr3 = new char[] { 'p', 'q', 'r' };       System.out.println(Arrays.equals(arr1, arr2));       System.out.println(Arrays.equals(arr2, arr3));       System.out.println(Arrays.equals(arr1, arr3));    } }  Output
false false true
Advertisements
 