Java String Starts Wtih startsWith(String prefix, String string, boolean caseInsensitive)

Here you can find the source of startsWith(String prefix, String string, boolean caseInsensitive)

Description

Check that string starts with specified prefix.

License

Open Source License

Declaration

public static boolean startsWith(String prefix, String string, boolean caseInsensitive) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**// w w w. jav  a  2  s . c  om
     * Check that string starts with specified prefix.
     * <p/>
     * <p>If {@code caseInsensitive == false} this check is equivalent
     * to {@link String#startsWith(String)}.
     * <p/>
     * <p>Otherwise {@code prefix} should be lower-case and check ignores
     * case of {@code string}.
     */
    public static boolean startsWith(String prefix, String string, boolean caseInsensitive) {
        if (caseInsensitive) {
            int prefixLength = prefix.length();
            if (string.length() < prefixLength) {
                return false;
            }
            return prefix.equals(string.substring(0, prefixLength).toLowerCase());
        } else {
            return string.startsWith(prefix);
        }
    }
}

Related

  1. startsWith(String comparee, char comparant)
  2. startsWith(String inStart, String inValue)
  3. startsWith(String n, char tag)
  4. startsWith(String partial, String possible)
  5. startsWith(String path, String prefix)
  6. startsWith(String receiver, String... needles)
  7. startsWith(String s, boolean caseIgnore, String... args)
  8. startsWith(String s, char begin)
  9. startsWith(String s, char c)