How to filter duplicate values emitted by observable in RXJava?

后端 未结 2 550
南笙
南笙 2021-02-19 00:29

I have a collection of objects, where i want to suppress duplicate items. I know about Distinct operator, but if i am not mistaken it compare items by properly overrided hashcod

2条回答
  •  时光说笑
    2021-02-19 01:04

    Not sure if simplest way but you can do it with reduce. Reduce takes a collection and an action. Within the action you are responsible for adding the elements to the collection yourself. There you can do whatever logic you'd like and conditionally add elements to the collection.

提交回复
热议问题