Java Array Starts With startsWith(char[] str1, String str2)

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

Description

Returns true if a prefix of the character array is the same as contents of a string.

License

Open Source License

Declaration

public static final boolean startsWith(char[] str1, String 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:// ww  w .j  av a 2s  . co  m
 *     IBM Corporation - initial API and implementation
 *     Andrew Ferguson (Symbian)
 *     Markus Schorn (Wind River Systems)
 *     Sergey Prigogin (Google)
 *******************************************************************************/

public class Main {
    /**
     * Returns {@code true} if a prefix of the character array is the same as contents
     * of a string.
     * @since 5.4
     */
    public static final boolean startsWith(char[] str1, String str2) {
        int len = str2.length();
        if (str1.length < len)
            return false;
        for (int i = 0; i < len; i++) {
            if (str1[i] != str2.charAt(i)) {
                return false;
            }
        }
        return true;
    }
}

Related

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