Here you can find the source of startsWith(final String str, final char prefix)
Parameter | Description |
---|---|
str | the String to check, may be null |
prefix | the first char to find |
public static boolean startsWith(final String str, final char prefix)
//package com.java2s; public class Main { /**/*from www .ja va 2 s . c o m*/ * Check if a String starts with a specified prefix character. <code>nulls</code> are handled * without exceptions. The comparison is case sensitive. * * <pre> * StringUtil.startsWith(null, 'a') = false * StringUtil.startsWith("", 0) = false * StringUtil.startsWith("", 'a') = false * StringUtil.startsWith("abcdef", 'a') = true * StringUtil.startsWith("ABCDEF", 'a') = false * StringUtil.startsWith("ABCDEF", 'B') = false * </pre> * * @param str * the String to check, may be null * @param prefix * the first char to find * @return true, if the String starts with the prefix */ public static boolean startsWith(final String str, final char prefix) { return str != null && str.length() > 0 && str.charAt(0) == prefix; } }