Java Tutorial 52 - The String Class 4-5

Publicado em: 04 Fevereiro 2020
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line Java Tutorial 52 - The String Class 4-5 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Ken 04 Fevereiro 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 16 vezes e gostou 1 espectadores. Boa visualização!