Java Array Equal equals(char[] left, int offsetLeft, char[] right, int offsetRight, int length)

Here you can find the source of equals(char[] left, int offsetLeft, char[] right, int offsetRight, int length)

Description

See if two array slices are the same.

License

Open Source License

Parameter

Parameter Description
left The left array to compare
offsetLeft The offset into the array. Must be positive
right The right array to compare
offsetRight the offset into the right array. Must be positive
length The length of the section of the array to compare

Return

true if the two arrays, starting at their respective offsets, are equal

Declaration

public static boolean equals(char[] left, int offsetLeft, char[] right, int offsetRight, int length) 

Method Source Code

//package com.java2s;
/** //  w ww  . j  a  v a 2 s .c o m
 * Returns an array size >= minTargetSize, generally
 *  over-allocating exponentially to achieve amortized
 *  linear-time cost as the array grows.
 *
 *  NOTE: this was originally borrowed from Python 2.4.2
 *  listobject.c sources (attribution in LICENSE.txt), but
 *  has now been substantially changed based on
 *  discussions from java-dev thread with subject "Dynamic
 *  array reallocation algorithms", started on Jan 12
 *  2010.
 *
 * @param minTargetSize Minimum required value to be returned.
 * @param bytesPerElement Bytes used by each element of
 * the array.  See constants in {@link JvmUtil}.
 *
 */

public class Main {
    /**
     * See if two array slices are the same.
     *
     * @param left        The left array to compare
     * @param offsetLeft  The offset into the array.  Must be positive
     * @param right       The right array to compare
     * @param offsetRight the offset into the right array.  Must be positive
     * @param length      The length of the section of the array to compare
     * @return true if the two arrays, starting at their respective offsets, are equal
     * 
     * @see java.util.Arrays#equals(char[], char[])
     */
    public static boolean equals(char[] left, int offsetLeft, char[] right, int offsetRight, int length) {
        if ((offsetLeft + length <= left.length) && (offsetRight + length <= right.length)) {
            for (int i = 0; i < length; i++) {
                if (left[offsetLeft + i] != right[offsetRight + i]) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * See if two array slices are the same.
     *
     * @param left        The left array to compare
     * @param offsetLeft  The offset into the array.  Must be positive
     * @param right       The right array to compare
     * @param offsetRight the offset into the right array.  Must be positive
     * @param length      The length of the section of the array to compare
     * @return true if the two arrays, starting at their respective offsets, are equal
     * 
     * @see java.util.Arrays#equals(byte[], byte[])
     */
    public static boolean equals(byte[] left, int offsetLeft, byte[] right, int offsetRight, int length) {
        if ((offsetLeft + length <= left.length) && (offsetRight + length <= right.length)) {
            for (int i = 0; i < length; i++) {
                if (left[offsetLeft + i] != right[offsetRight + i]) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * See if two array slices are the same.
     *
     * @param left        The left array to compare
     * @param offsetLeft  The offset into the array.  Must be positive
     * @param right       The right array to compare
     * @param offsetRight the offset into the right array.  Must be positive
     * @param length      The length of the section of the array to compare
     * @return true if the two arrays, starting at their respective offsets, are equal
     * 
     * @see java.util.Arrays#equals(char[], char[])
     */
    public static boolean equals(int[] left, int offsetLeft, int[] right, int offsetRight, int length) {
        if ((offsetLeft + length <= left.length) && (offsetRight + length <= right.length)) {
            for (int i = 0; i < length; i++) {
                if (left[offsetLeft + i] != right[offsetRight + i]) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}

Related

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