Java String equals() Metodo
Esempio
Confronta le stringhe per scoprire se sono uguali:
String myStr1 = "Hello";
String myStr2 = "Hello";
String myStr3 = "Another String";
System.out.println(myStr1.equals(myStr2)); // Returns true because they are equal
System.out.println(myStr1.equals(myStr3)); // false
Definizione e utilizzo
Il equals()
metodo confronta due stringhe e restituisce true se le stringhe sono uguali e false in caso contrario.
Suggerimento: usa il metodo compareTo() per confrontare due stringhe lessicograficamente.
Sintassi
public boolean equals(Object anotherObject)
Valori dei parametri
Parameter | Description |
---|---|
anotherObject | An Object , representing the other string
to be compared |
Dettagli tecnici
Ritorna: | Un boolean valore:
|
---|---|
Sostituzioni: | equals in classeObject |
❮ Metodi di stringa