Java String. EndsWith () method Usage Example tutorial, the method returns a true if the argument represents a sequence of characters represented by the suffix of the character sequence, otherwise returns false
Describe
java.lang.String. EndsWith The () method returns the test whether the string ends with the specified suffix Sffix
Statement
The following is the declaration java.lang.String. EndsWith () method
EndsWith (String suffix)
Parameters
return value
The method returns a true if the argument represents a sequence of characters that is the suffix of the character sequence represented by the object, otherwise false is returned.
Abnormal
Instance
The following example shows the java.lang.String used. EndsWith () method.
Package Com.yiibai;import java.lang.*;p ublic class Stringdemo {public static void Main (string[] args) { String s TR = "www.yiibai.com"; System.out.println (str); The end string to is checked string endstr1 = ". com"; String endstr2 = ". org"; Checks that string str ends with given substring boolean retval1 = str.endsWith(ENDSTR1); Boolean retval2 = str.endsWith(ENDSTR2); Prints true if the string ends with given substring System.out.println ("ends with" + Endstr1 + "?" + Retval1); C13/>system.out.println ("ends with" + Endstr2 + "?" + Retval2);} }
Let's compile and run the above program, which will produce the following results:
Www.yiibai.comends with. com? Trueends with. org? False
Java String.endswith () method