0

I have a custom object list like bellow :

public List<Message> getMessages() {
    return messages;
}

And :

public class Message {

    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("useridfrom")
    @Expose
    private String useridfrom;
    @SerializedName("useridto")
    @Expose
    private String useridto;
    @SerializedName("subject")
    @Expose
    private String subject;
    @SerializedName("fullmessage")
    @Expose
    private String fullmessage;
    @SerializedName("fullmessageformat")
    @Expose
    private String fullmessageformat;
    @SerializedName("fullmessagehtml")
    @Expose
    private String fullmessagehtml;
    @SerializedName("smallmessage")
    @Expose
    private String smallmessage;
    @SerializedName("notification")
    @Expose
    private String notification;
    @SerializedName("contexturl")
    @Expose
    private Object contexturl;
    @SerializedName("contexturlname")
    @Expose
    private Object contexturlname;
    @SerializedName("timecreated")
    @Expose
    private String timecreated;
    @SerializedName("timeuserfromdeleted")
    @Expose
    private String timeuserfromdeleted;
    @SerializedName("timeusertodeleted")
    @Expose
    private String timeusertodeleted;
    @SerializedName("component")
    @Expose
    private String component;
    @SerializedName("eventtype")
    @Expose
    private String eventtype;
    @SerializedName("userfromfirstnamephonetic")
    @Expose
    private String userfromfirstnamephonetic;
    @SerializedName("userfromlastnamephonetic")
    @Expose
    private String userfromlastnamephonetic;
    @SerializedName("userfrommiddlename")
    @Expose
    private String userfrommiddlename;
    @SerializedName("userfromalternatename")
    @Expose
    private String userfromalternatename;
    @SerializedName("userfromfirstname")
    @Expose
    private String userfromfirstname;
    @SerializedName("userfromlastname")
    @Expose
    private String userfromlastname;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUseridfrom() {
        return useridfrom;
    }

    public void setUseridfrom(String useridfrom) {
        this.useridfrom = useridfrom;
    }

    public String getUseridto() {
        return useridto;
    }

    public void setUseridto(String useridto) {
        this.useridto = useridto;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getFullmessage() {
        return fullmessage;
    }

    public void setFullmessage(String fullmessage) {
        this.fullmessage = fullmessage;
    }

    public String getFullmessageformat() {
        return fullmessageformat;
    }

    public void setFullmessageformat(String fullmessageformat) {
        this.fullmessageformat = fullmessageformat;
    }

    public String getFullmessagehtml() {
        return fullmessagehtml;
    }

    public void setFullmessagehtml(String fullmessagehtml) {
        this.fullmessagehtml = fullmessagehtml;
    }

    public String getSmallmessage() {
        return smallmessage;
    }

    public void setSmallmessage(String smallmessage) {
        this.smallmessage = smallmessage;
    }

    public String getNotification() {
        return notification;
    }

    public void setNotification(String notification) {
        this.notification = notification;
    }

    public Object getContexturl() {
        return contexturl;
    }

    public void setContexturl(Object contexturl) {
        this.contexturl = contexturl;
    }

    public Object getContexturlname() {
        return contexturlname;
    }

    public void setContexturlname(Object contexturlname) {
        this.contexturlname = contexturlname;
    }

    public String getTimecreated() {
        return timecreated;
    }

    public void setTimecreated(String timecreated) {
        this.timecreated = timecreated;
    }

    public String getTimeuserfromdeleted() {
        return timeuserfromdeleted;
    }

    public void setTimeuserfromdeleted(String timeuserfromdeleted) {
        this.timeuserfromdeleted = timeuserfromdeleted;
    }

    public String getTimeusertodeleted() {
        return timeusertodeleted;
    }

    public void setTimeusertodeleted(String timeusertodeleted) {
        this.timeusertodeleted = timeusertodeleted;
    }

    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    public String getEventtype() {
        return eventtype;
    }

    public void setEventtype(String eventtype) {
        this.eventtype = eventtype;
    }

    public String getUserfromfirstnamephonetic() {
        return userfromfirstnamephonetic;
    }

    public void setUserfromfirstnamephonetic(String userfromfirstnamephonetic) {
        this.userfromfirstnamephonetic = userfromfirstnamephonetic;
    }

    public String getUserfromlastnamephonetic() {
        return userfromlastnamephonetic;
    }

    public void setUserfromlastnamephonetic(String userfromlastnamephonetic) {
        this.userfromlastnamephonetic = userfromlastnamephonetic;
    }

    public String getUserfrommiddlename() {
        return userfrommiddlename;
    }

    public void setUserfrommiddlename(String userfrommiddlename) {
        this.userfrommiddlename = userfrommiddlename;
    }

    public String getUserfromalternatename() {
        return userfromalternatename;
    }

    public void setUserfromalternatename(String userfromalternatename) {
        this.userfromalternatename = userfromalternatename;
    }

    public String getUserfromfirstname() {
        return userfromfirstname;
    }

    public void setUserfromfirstname(String userfromfirstname) {
        this.userfromfirstname = userfromfirstname;
    }

    public String getUserfromlastname() {
        return userfromlastname;
    }

    public void setUserfromlastname(String userfromlastname) {
        this.userfromlastname = userfromlastname;
    }

}

How can I count duplicate items : useridfrom and useridto.

I like use from RXJava for better performance an do in background.

marianosimone
  • 3,366
  • 26
  • 32
  • If i understood correctly, You can override `equals()` for `Message` and check for equality. – ADM Apr 22 '18 at 14:22
  • Yes.But I need to best way and do in background. –  Apr 22 '18 at 14:23
  • AFAIK I think this the best way to compare two object(holding same properties) for equality. I do not have much idea about `RXJava`. – ADM Apr 22 '18 at 14:26
  • I like see your response. please write your idea. Thanks a lot –  Apr 22 '18 at 14:28
  • Well i can not write an answer right now . You can try https://stackoverflow.com/questions/16462644/java-duplicate-objects-getting-added-to-set Or Similar posts. Either Hold data in `Set` and modify your model class as per link . Or with `List` you have to loop through to remove duplicates. – ADM Apr 22 '18 at 14:31
  • 1
    Can you specify what you actually want? Just count how many duplicates there are? (e.g. [1,2,3,1,1] is a list that has 2 duplicate elements, but of only 1 value... do you care about the former or the later?) Also, it would help if you could remove all unrelated code, so it's easier for people to read your question (e.g. we don't need all of your class' definition, just the relevant fields) – marianosimone Apr 23 '18 at 06:10

0 Answers0