The equals() and toString() methods in Java, here I will write a small example to help everyone learn and understand this part of the knowledge.
/* The parent class of all objects Method in Object: equals() Comparison method of whether the object is the same toString() String representation of the object*/class Person{ String name; int age; Person(String name, int age) { this.name = name; this.age = age; }}class ObjectDemo{ public static void main(String[] args) { Person p = new Person("lixin", 27); Person q = new Person("jingxiaoqing", 21); if(p.equals(q)) { System.out.println("p = q"); }else { System.out.println("nothing"); } System.out.println("p.toString : " + p.toString()); }}Thank you for reading, I hope it can help you. Thank you for your support for this site!