Java String Starts Wtih startsWith(String str, String prefix)

Here you can find the source of startsWith(String str, String prefix)

Description

Tests if the provided string starts with the specified prefix.
Comparison is case-sensitive.

License

Open Source License

Parameter

Parameter Description
str The string to validate against.
prefix The value to use in the validation.

Return

True if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals(Object) method.

Declaration

public static boolean startsWith(String str, String prefix) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  ww . j av  a 2s. c  om
     * Tests if the provided string starts with the specified prefix.<br/>
     * Comparison is <i>case-sensitive</i>.
     * 
     * @param str
     *          The string to validate against.
     * @param prefix
     *          The value to use in the validation.
     * @return True if the character sequence represented by the argument is a prefix of the character sequence represented by this
     *         string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this
     *         String object as determined by the equals(Object) method.
     * @see #startsWithIgnoreCase(String, String)
     */
    public static boolean startsWith(String str, String prefix) {
        if (str != null && prefix != null) {
            return str.startsWith(prefix);
        }
        return (str == null && prefix == null);
    }
}

Related

  1. startsWith(String str, char c)
  2. startsWith(String str, char prefix)
  3. startsWith(String str, char prefix)
  4. startsWith(String str, String mark, int paramInt)
  5. startsWith(String str, String prefix)
  6. startsWith(String str, String prefix)
  7. StartsWith(String str, String prefix)
  8. startsWith(String str, String prefix, boolean ignoreCase)
  9. startsWith(String str, String prefix, boolean ignoreCase)