Results 1 to 2 of 2
  1. #1
    jing-yi is offline Member
    Join Date
    May 2011
    Posts
    35
    Rep Power
    0

    Default Omit duplicate object that has same value in a collection class

    Good day...

    Set is able to omit duplicate value.

    But, let say an object carry two attributes: attribute 1 and attribute2 and later it is added to a collection class.

    Is anyone of you able to omit the object with same attribute 1 and attribute2?

    Object obj1 = new Object();
    obj1.attribute1 = "abc";
    obj1.attribute2 = "def";

    collection.add(obj1);

    Object obj2 = new Object();
    obj2.attribute1 = "abc";
    obj2.attribute2 = "def";

    collection.add(obj2);

    Here, I hope the collection variable would carry one obj only instead of 2 obj...

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Omit duplicate object that has same value in a collection class

    Crossposted at OTN...don't have the link handy I'm afraid.
    There's a few answers over there, so no point anyone here looking at this I suppose.

Similar Threads

  1. Preventing duplicate instances of an object
    By monkeyhead in forum New To Java
    Replies: 2
    Last Post: 11-07-2011, 07:28 PM
  2. How to update object in Collection.
    By maynul in forum New To Java
    Replies: 0
    Last Post: 10-28-2011, 06:14 PM
  3. How to Remove Duplicate object from collection
    By santhoskumara in forum Advanced Java
    Replies: 4
    Last Post: 08-04-2010, 07:07 PM
  4. Cannot insert duplicate key row in object
    By losintikfos in forum New To Java
    Replies: 3
    Last Post: 05-07-2009, 09:43 AM
  5. How do I omit an object when serializing?
    By Hasan in forum Advanced Java
    Replies: 1
    Last Post: 05-31-2007, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •