Object-oriented 15.3String class-common functions-judging

Source: Internet
Author: User

/*3. Judging
* 3.1 Two string content is the same?
* Boolean equals (Object obj) (the argument is an object, not a string, because Equals is the Equals method that overrides object, what is the argument of the parent class, and what argument does the equals have?)
* Boolean equalsignorecase (String str) compares this string to another string, regardless of the case.
*
* 3.2 Does the string contain the specified string?
* Boolean contains (Charsequence s) returns True when and only if this string contains a sequence of specified char values.
*
* 3.3 Does the string begin with the specified string? Do you want to end with the specified string?
* Boolean startsWith (string prefix) tests whether this string starts with the specified prefix.
* EndsWith (string suffix) tests whether this string ends with the specified suffix.
* */

public static void Main (string[] args) {
3.1
String s= "ABC";
System.out.println (S.equals ("ABC". toUpperCase ()));//false
System.out.println (S.equalsignorecase ("ABC")),//true,equalsignorecase (""), this method ignores case and determines whether the contents of the string are the same
3.2
System.out.println (S.contains ("a"));//true,s contains A,
3.3
String str= "Arraydamo.java";
System.out.println (Str.startswith ("Arraydamo"));//I want to find all the files that start with Arraydamo.
System.out.println (Str.endswith (". Java"));//I want to find all the files that end in. java.
System.out.println (Str.contains ("Damo"));//I want to find a file that contains Damo characters
}

Object-oriented 15.3String class-common functions-judging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.