Home Tutorial Java Corejava Compare two char array in java

 
 

Share on Google+Share on Google+
Compare two char array in java
Posted on: June 29, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Compare two char array in java:


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.

Posted on: June 29, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com