Java Array Region Match arrayRegionMatches(char[] source, int sourceStart, char[] target, int targetStart, int len)

Here you can find the source of arrayRegionMatches(char[] source, int sourceStart, char[] target, int targetStart, int len)

Description

Convenience utility to compare two char[]s.

License

Open Source License

Parameter

Parameter Description
len the length to compare. The start indices and start+len must be valid.

Declaration

public final static boolean arrayRegionMatches(char[] source, int sourceStart, char[] target, int targetStart,
        int len) 

Method Source Code

//package com.java2s;
/*/* w w w.  ja v a 2 s  .c  om*/
 * @(#)Utility.java   1.4 05/11/17
 *
 * Portions Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    /**
     * Convenience utility to compare two char[]s.
     * @param len the length to compare.
     * The start indices and start+len must be valid.
     */
    public final static boolean arrayRegionMatches(char[] source, int sourceStart, char[] target, int targetStart,
            int len) {
        int sourceEnd = sourceStart + len;
        int delta = targetStart - sourceStart;
        for (int i = sourceStart; i < sourceEnd; i++) {
            if (source[i] != target[i + delta])
                return false;
        }
        return true;
    }
}

Related

  1. arrayRegionMatches(Object[] source, int sourceStart, Object[] target, int targetStart, int len)
  2. arrayRegionMatches(Object[] source, int sourceStart, Object[] target, int targetStart, int len)
  3. arrayRegionsEqual(boolean[] a, int aoff, int alen, boolean[] b, int boff, int blen)