简体   繁体   中英

How to set the equality comparison between two objects present in an ArrayList?

如何设置存储在ArrayList类型的对象中的两个由我定义的对象之间的相等比较行为?

For this there exists in the Java language two fundamental methods called equals (...) and hashCode () that are declared in class java.lang.Object by default and are part of the core library of Java.

You should implement these two methods in your classes that need to be compared!

The equals() method is used to compare if one object is equal to the other.

The hashCode() method is used to generate an ID number corresponding to the object.

See more in: https://docs.oracle.com/javase/7/docs/api/java/util/List.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM