Java Tutorial 52 - The String Class 4-5

Publié le: 04 février 2020
sur la chaîne: Ken
16
1

The String Class
is a sequence of characters.
is actually a predefined class in the Java library.

Comparing Strings

String s1 = "Welcome to Java";
String s2 = "Welcome to Java";
String s3 = "Welcome to C";

Method Description
equals(s1) Returns true if this string is equal to string s1.
e.g.,
s1.equals(s2); // true
s1.equals(s3); // false

equalsIgnoreCase(s1) Returns true if this string is equal to string s1; it is case insensitive.
s1.equalsIgnoreCase(s2); // true
s1.equalsIgnoreCase(s3); // false

compareTo(s1) Returns an integer greater than 0, equal to 0, or less than 0 to indicate
whether this string is greater than, equal to, or less than s1.
e.g.
s1.compareTo(s2); // 0
s1.compareTo(s3); // 7

compareToIgnoreCase(s1) Same as compareTo except that the comparison is case insensitive.
e.g.
s1.compareToIgnoreCase(s2); // 0
s1.compareToIgnoreCase(s3); // 7

startsWith(prefix) Returns true if this string starts with the specified prefix.
e.g.,
s1.startsWith("We"); // true
s1.startsWith("we"); // false

endsWith(suffix) Returns true if this string ends with the specified suffix.
e.g.,
s1.endsWith("Java"); // true
s1.endsWith("java"); // false

contains(s1) Returns true if s1 is a substring in this string.
e.g.,
s1.contains("to"); // true
s1.contains("To"); // false


Sur cette page du site, vous pouvez voir la vidéo en ligne Java Tutorial 52 - The String Class 4-5 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Ken 04 février 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 16 fois et il a aimé 1 téléspectateurs. Bon visionnage!