Here you can find the source of startsWithIgnoreCase(String str, String prefix)
Parameter | Description |
---|---|
str | The String to check. |
prefix | The prefix to check the String for. |
public static boolean startsWithIgnoreCase(String str, String prefix)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . j a va 2 s. co m*/ * Checks if the given String begins with the given prefix, ignoring case. * * @param str The String to check. * @param prefix The prefix to check the String for. * * @return True if the given String begins with the given prefix, otherwise false. */ public static boolean startsWithIgnoreCase(String str, String prefix) { if (str == null) throw new IllegalArgumentException("Parameter 'str' cannot be null!"); if (prefix == null) throw new IllegalArgumentException("Parameter 'prefix' cannot be null!"); if (str.length() < prefix.length()) return false; int offset = (prefix.length() + 1 <= str.length()) ? prefix.length() : str.length(); String beginning = str.substring(0, offset); return beginning.equalsIgnoreCase(prefix); } }