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