Java – find unique entries in the list
•
Java
List<Object> listObj = new ArrayList<Object[]>();
List<Object> listObj = new ArrayList<Object[]>(); listObj.add(new Object[]{1,"abc",new Date(21/1/2001)}); listObj.add(new Object[]{1,new Date(21/1/2001)}); listObj.add(new Object[]{2,"acc",new Date(21/1/2001)}); Set<Object[]> unique = new HashSet<Object[]>(); unique.addAll();
I look forward to:
{1,abc,21/1/2001},{2,acc,21/1/2001}
Instead, I get:
{1,{1,(21/1/2001},21/1/2001}
How do I find a unique entry in this example?
Solution
Arrays in java do not have the concept of equality that allows them to work You need to define a custom class with numbers, strings, and dates, and implement equals / hashcode yourself to allow it to work
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
二维码