Share on Google+Share on Google+

Compare two char array in java

This tutorial helps you to know how to compare two char array in java.


This tutorial demonstrate how to compare two character array are equal or not. The Arrays.equals(c1, c2) helps to compare it and return boolean value.


import java.util.Arrays;

public class Comp2CharArray {
  public static void main(String[] args) {
    char[] c1 = new char[] { 'a''b''c''d' };
    char[] c2 = new char[] { 'a''b''c''e' };
    System.out.println(Arrays.equals(c1, c2));
    char[] a1 = new char[] { 'a''b''c''d' };
    char[] a2 = new char[] { 'a''b''c''d' };
    System.out.println(Arrays.equals(a1, a2));


Download this code


Posted on: June 29, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.