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

Apache 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 a2s .c  o m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

Related

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