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
Auf dieser Seite können Sie das Online-Video Java Tutorial 52 - The String Class 4-5 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Ken 04 Februar 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 16 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!