0

I have a list which contains duplicates & need to remove them. My list is of the form

List<List<XSSFCell>> results;

A sample of data stored in the List 'results' is:

  • [ABC, 123, 22-Apr-2016]
  • [DEF, 456, 22-Apr-2016]
  • [ABC, 123, 22-Apr-2016]
  • [ABC, 123, 10-Jan-2016]

Based on this Link I tried the below code:

Set<List<XSSFCell>> hashSetResults = new LinkedHashSet<>(results);

Expected output is:

  • [ABC, 123, 22-Apr-2016]
  • [DEF, 456, 22-Apr-2016]
  • [ABC, 123, 10-Jan-2016]

But it is not removing the duplicate & the entire list gets saved in the Set. Hope am clear on the issue faced, seek guidance.

Community
  • 1
  • 1
iCoder
  • 1,406
  • 6
  • 16
  • 35
  • This is because because you are passing list of objects, how to fix it need a bit of thinking – Maytham Fahmi Apr 28 '16 at 14:42
  • Are the individual `XSSFCell` entries equal (using the `equals()` method)? If the lists were actually equal (via `equals()`) I think your approach should work. – Tim Biegeleisen Apr 28 '16 at 14:49
  • I checked the JavaDoc and an `XSSFCell` object has a row and column index. So even though two cells in two lists might be logically equal, they can not be equal via `equals()`. – Tim Biegeleisen Apr 28 '16 at 14:52

1 Answers1

0

you should override XSSFCell equal method.

ugurdonmez
  • 154
  • 1
  • 9