Compare two char array in java

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

 
 

Share on Google+Share on Google+

Compare two char array in java

Ads

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

Description:

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.

Code:

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));
  }
}

Output:

Download this code

Advertisements

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