1

When the code flow gets to the removeIf() logic the code breaks and it doesn't return anything as if it was a lang error. Please use the same code logic if possible.

public static SalmonSumario[] filterSummario(SalmonSumario[] salmon){
  Set<String> filter = new TreeSet<>();
  
  List<SalmonSumario> salmonSum = Arrays.asList(salmon);
  
  salmonSum.removeIf(array -> !filter.add(array.getSalmonNumber()));
  
  return salmonSum.toArray(new SalmonSumario[0]);
}
Didier L
  • 18,905
  • 10
  • 61
  • 103
  • 1
    @Alias Cartellano they said `Please use the same code logic if possible` and `distinct()` doesn't work for removing distinct attributes. – dan1st Jan 05 '22 at 19:52
  • TBH the duplicate I linked explains the why of this “question”, but there is no real question asked here. If you are not just trying to understand why you get an error, a clear description of what you are trying to do and a clear error message would be welcome (although I assume it is the same exception as in the duplicate). “_Please use the same code logic if possible_” is not a very clear description of your requirements. – Didier L Jan 05 '22 at 20:35
  • @DidierL You are right, just reviewed and tried with your suggestion and it worked. Try to write an answer if you like so I can mark it as an answer. Thanks buddy. – Alex Rodriguez Jan 05 '22 at 20:43
  • The goal of marking duplicates is to avoid writing multiple times the same thing Note that I think your approach is not necessarily the best / the most efficient (depending on your requirements), but improving it might be a better fit for [codereview.se] instead. – Didier L Jan 05 '22 at 20:50

1 Answers1

0

The list returned by Arrays.asList() has a fixed length so you can't add nor remove elements, Therefore, you will have to wrap it with new ArrayList<>(Arrays.asList(salmon))