Common methods of judging the string class using practice

Source: Internet
Author: User

Some commonly used judgment methods are selected to be used in practice, followed by other new methods.

 PackageStringdemo;//analysis of the method of judging the string class//1:boolean equals ();//determine if strings are equal and case sensitive//2:boolean equalsignorecase (String anotherstring)//compares this string to another string, regardless of case//3.boolean contains (charsequence s)//determines whether a string object contains the specified string Public classStringdemo { Public Static voidMain (string[] args) {String sc= "HelloWorld"; //1:boolean equals (); //determine if strings are equal and case sensitiveSystem.out.println (Sc.equals ("HelloWorld")); System.out.println ("-----------------------"); //2:boolean equalsignorecase (String anotherstring)//compares this string to another string, regardless of caseSystem.out.println (Sc.equalsignorecase ("HelloWorld")); System.out.println ("-----------------------"); //3.boolean contains (charsequence s)//determines whether the string object contains the specified string (continuous)System.out.println (Sc.contains ("Hell")); System.out.println ("-----------------------"); //4.boolean endsWith (String suffix)//determines whether a string ends with a given characterSystem.out.println (Sc.endswith ("D")); System.out.println ("-----------------------"); //5.boolean startsWith (String prefix)//determines whether a string begins with a given stringSystem.out.println (Sc.startswith ("Hell")); System.out.println ("-----------------------"); //6.boolean isEmpty (); //determines whether a string is emptySystem.out.println (Sc.isempty ()); System.out.println ("-----------------------"); }}

Common methods of judging the string class using practice

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.