Java String Starts Wtih startsWithIgnoreCase(final String input, final String prefix)

Here you can find the source of startsWithIgnoreCase(final String input, final String prefix)

Description

Checks if a string starts with a given suffix.

License

Creative Commons License

Parameter

Parameter Description
input string to check
prefix suffix to check

Exception

Parameter Description
IllegalArgumentException if Input or Suffix is null

Return

true if string starts with a given suffix

Declaration

public static boolean startsWithIgnoreCase(final String input, final String prefix) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    /**//www. j ava  2 s .  c  o  m
     * Checks if a string starts with a given suffix.
     * @param input string to check
     * @param prefix suffix to check
     * @return true if string starts with a given suffix
     * @throws IllegalArgumentException if Input or Suffix is null
     */
    public static boolean startsWithIgnoreCase(final String input, final String prefix) {
        if (input == null)
            throw new IllegalArgumentException("Input cannot be null!");
        if (prefix == null)
            throw new IllegalArgumentException("Suffix cannot be null!");
        return input.startsWith(prefix)
                || input.length() >= prefix.length() && input.toLowerCase().startsWith(prefix.toLowerCase());
    }
}

Related

  1. startsWithHtml(Object object)
  2. startsWithIC(String s1, String... strings)
  3. startsWithIgnoreCase(final String base, final String start)
  4. startsWithIgnoreCase(final String haystack, final String needle)
  5. startsWithIgnoreCase(final String iFirst, final String iSecond)
  6. startsWithIgnoreCase(final String source, final String target)
  7. startsWithIgnoreCase(final String str, final String prefix)
  8. startsWithIgnoreCase(final String str, final String prefix)
  9. startsWithIgnoreCase(final String string, final String start)