Java – HashMap maps integer arrays by considering their values
•
Java
Given the following code, I get a null (what I want is "1234") But I hope there is a mapping that can treat the key as equal. If the content of int [] is equal (instead of considering the reference of int []), what should I do?
I open any map that allows to keep int [] as the key (including treemap), and the edge condition is that if this does not hinder the effectiveness of map access time
Solution
You cannot do this with arrays because they do not override equals() and hashcode() You should define your own class that wraps the array, which will override equals () and hashcode () or use list < integer > as the key
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
二维码