Java Array Equal equals(char[] str1, char[] str2)

Here you can find the source of equals(char[] str1, char[] str2)

Description

equals

License

Open Source License

Declaration

public static final boolean equals(char[] str1, char[] str2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  w w. j  a  v a2s  .  co  m*/
 *     IBM Corporation - initial API and implementation
 *     Andrew Ferguson (Symbian)
 *     Markus Schorn (Wind River Systems)
 *     Sergey Prigogin (Google)
 *******************************************************************************/

import java.util.Arrays;

public class Main {
    public static final boolean equals(char[] str1, char[] str2) {
        return Arrays.equals(str1, str2);
    }

    public static final boolean equals(char[][] strarr1, char[][] strarr2) {
        if (strarr1.length != strarr2.length) {
            return false;
        }
        for (int i = 0; i < strarr2.length; i++) {
            if (!Arrays.equals(strarr1[i], strarr2[i])) {
                return false;
            }
        }
        return true;
    }

    /**
     * Returns {@code true} if the contents of a character array are the same as contents
     * of a string.
     * @since 5.4
     */
    public static final boolean equals(char[] str1, String str2) {
        int length = str1.length;
        if (str2.length() != length)
            return false;

        for (int i = 0; i < length; i++) {
            if (str1[i] != str2.charAt(i))
                return false;
        }
        return true;
    }

    /**
     * Returns {@code true} if the contents of a section of a character array are the same as
     * contents of a string.
     * @since 5.5
     */
    public static final boolean equals(char[] str1, int start1,
            int length1, String str2) {
        if (length1 != str2.length() || str1.length < length1 + start1)
            return false;
        for (int i = 0; i < length1; ++i) {
            if (str1[start1++] != str2.charAt(i))
                return false;
        }
        return true;
    }

    /**
     * Returns {@code true} if the contents of a section of a character array are the same as
     * contents of another character array.
     */
    public static final boolean equals(char[] str1, int start1,
            int length1, char[] str2) {
        if (length1 != str2.length || str1.length < length1 + start1)
            return false;
        if (str1 == str2 && start1 == 0)
            return true;
        for (int i = 0; i < length1; ++i) {
            if (str1[start1++] != str2[i])
                return false;
        }

        return true;
    }

    public static final boolean equals(char[] str1, int start1,
            int length1, char[] str2, boolean ignoreCase) {
        if (!ignoreCase)
            return equals(str1, start1, length1, str2);

        if (length1 != str2.length || str1.length < start1 + length1)
            return false;

        for (int i = 0; i < length1; ++i) {
            if (Character.toLowerCase(str1[start1++]) != Character
                    .toLowerCase(str2[i]))
                return false;
        }
        return true;
    }
}

Related

  1. equals(byte[] data1, byte[] data2)
  2. equals(byte[] first, byte[] second)
  3. equals(byte[] first, byte[] second)
  4. equals(char[] left, int offsetLeft, char[] right, int offsetRight, int length)
  5. equals(char[] left, int offsetLeft, char[] right, int offsetRight, int length)
  6. equals(char[][] c1, char[][] c2)
  7. equals(Collection asCollection, String[] values)
  8. equals(double[][] xs, double[][] ys)
  9. equals(final byte[] a, final byte[] b)