Java Array Starts With startsWith(char[] src, char[] find, int startAt)

Here you can find the source of startsWith(char[] src, char[] find, int startAt)

Description

Test whether 'find' can be found at position 'startPos' in the string 'src'.

License

Mozilla Public License

Declaration

public static boolean startsWith(char[] src, char[] find, int startAt) 

Method Source Code

//package com.java2s;
/*****************************************************************************************
 * *** BEGIN LICENSE BLOCK *****//w w  w.j a  v a 2  s .  c  o m
 *
 * Version: MPL 2.0
 *
 * echocat Jomon, Copyright (c) 2012-2013 echocat
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * *** END LICENSE BLOCK *****
 ****************************************************************************************/

public class Main {
    /**
     * Test whether 'find' can be found at position 'startPos' in the string 'src'.
     */
    public static boolean startsWith(char[] src, char[] find, int startAt) {
        int startPos = startAt;
        boolean result = true;

        // Check ranges
        if (src.length < startPos + find.length) {
            result = false;
        } else {
            final int max = find.length;
            for (int a = 0; a < max && result; a++) {
                if (src[startPos] != find[a]) {
                    result = false;
                }
                startPos++;
            }
        }
        return result;
    }
}

Related

  1. startsWith(byte[] source, int offset, byte[] match)
  2. startsWith(byte[] target, byte[] search, int offset)
  3. startsWith(byte[] target, int offset, byte[] litmusPaper)
  4. startsWith(char s[], int len, String prefix)
  5. startsWith(char[] prefix, char[] other)
  6. startsWith(char[] str1, String str2)
  7. startsWith(final byte[] array, final byte[] prefix)
  8. startsWith(final byte[] str, int startIndex, int endIndex, final byte ch)
  9. startsWithGaps(final byte[] aFrag, final int numStartGaps)