Here you can find the source of startsWith(String str, String prefix)
Parameter | Description |
---|---|
str | The string to validate against. |
prefix | The value to use in the validation. |
public static boolean startsWith(String str, String prefix)
//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); } }