Method of removing the same object element from the ArrayList container

I found the retainAll method on the Internet

Then add it to the code

Then I found that I can't. I checked a lot of things and found that the code is right. I just need to rewrite the equals method.

I don't know why, because the custom class book used in the small demo written earlier, as follows, can be used normally

Whatever, I'm going to find the source code of collection,

After overriding the equals method in employee.

As follows:

The above code can run normally.

The above is the whole content of the method of removing the same object elements in the ArrayList container brought by Xiaobian. I hope it will help you and support more programming tips~

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>