Java Array Starts With startsWith(char s[], int len, String prefix)

Here you can find the source of startsWith(char s[], int len, String prefix)

Description

Returns true if the character array starts with the suffix.

License

Open Source License

Parameter

Parameter Description
s Input Buffer
len length of input buffer
prefix Prefix string to test

Return

true if s starts with prefix

Declaration

public static boolean startsWith(char s[], int len, String prefix) 

Method Source Code

//package com.java2s;
/*// ww w.j  a  va 2s .co  m
 * Carrot2 project.
 *
 * Copyright (C) 2002-2016, Dawid Weiss, Stanis?aw Osi?ski.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

public class Main {
    /**
     * Returns true if the character array starts with the suffix.
     * 
     * @param s Input Buffer
     * @param len length of input buffer
     * @param prefix Prefix string to test
     * @return true if <code>s</code> starts with <code>prefix</code>
     */
    public static boolean startsWith(char s[], int len, String prefix) {
        final int prefixLen = prefix.length();
        if (prefixLen > len)
            return false;
        for (int i = 0; i < prefixLen; i++)
            if (s[i] != prefix.charAt(i))
                return false;
        return true;
    }
}

Related

  1. startsWith(byte[] source, byte[] match)
  2. startsWith(byte[] source, byte[] match)
  3. startsWith(byte[] source, int offset, byte[] match)
  4. startsWith(byte[] target, byte[] search, int offset)
  5. startsWith(byte[] target, int offset, byte[] litmusPaper)
  6. startsWith(char[] prefix, char[] other)
  7. startsWith(char[] src, char[] find, int startAt)
  8. startsWith(char[] str1, String str2)
  9. startsWith(final byte[] array, final byte[] prefix)