logo

Metoda Java znakova jednako().

Metoda equals(Object obj) klase znakova uspoređuje objekt s navedenim objektom. Rezultat je istinit ako i samo ako argument nije null i objekt Character ima istu vrijednost char kao što je predstavljeno objektom.

Sintaksa

 public boolean equals(Object obj) 

Parametar

Gornja metoda zahtijeva samo jedan parametar:

Objekt koji treba usporediti.

Povratna vrijednost

Metoda equals(Object obj) vraća true ako su objekti isti. U suprotnom, metoda vraća false.

Primjer 1

 public class JavaCharcterEqualsExample1 { public static void main(String[] args) { //Create a Character Character charValue = new Character('A'); // Create an Object Object obj = new Character('A'); // Test the equality for two values if (charValue.equals(obj)) { System.err.println('They are equal.'); } else { System.err.println('They are not equal.'); } } } 
Testirajte sada

Izlaz:

 They are equal. 

Primjer 2

 public class JavaCharacterEqualsExample2 { public static void main(String[] args) { //Create a Character Character charValue = new Character('B'); // Create an Object Object obj1 = new Character('C'); // Test the equality for two values if (charValue.equals(obj1)) { System.err.println('They are equal.'); } else { System.err.println('They are not equal.'); } } } 
Testirajte sada

Izlaz:

 They are not equal. 

Primjer 3

 public class JavaCharacterEqualsExample3 { public static void main(String[] args) { //Create a Character Character charValue = new Character('1'); // Create an Object Object obj = new Character('1'); // Test the equality for two values if (charValue.equals(obj)) { System.err.println('The numbers are equal.'); } else { System.err.println('The numbers are not equal.'); } } } 
Testirajte sada

Izlaz:

 The numbers are equal. 

Primjer 4

 public class JavaCharacterEqualsExample4 { public static void main(String[] args) { //Create a Character Character charValue = new Character('2'); // Create an Object Object obj = new Character('3'); // Test the equality for two values if (charValue.equals(obj)) { System.err.println('The numbers are equal.'); } else { System.err.println('The numbers are not equal.'); } } } 
Testirajte sada

Izlaz:

 The numbers are not equal.