Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: efficient way of checking duplicates

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default efficient way of checking duplicates

    hi, i was wondering if someone could give me an efficient way of checking and removing duplicates.

    basically i have this giant file which parses for IDs and Groups Num.

    The condition is that I can have 2 different IDs go into the same group number, but I cannot have 2 of the same IDs (think of it more as repeated) go into the same group.

    ie.

    ID Group Num
    150 200
    180 200

    would be valid

    or

    ID Group Num
    150 200
    150 201

    but

    ID Group Num
    150 200
    150 200

    would not be.

    thanks so much = )


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: efficient way of checking duplicates

    Use a Set, a Map, or combination of the two. In this case, a simple Map keyed with GroupNum and valued with a Set (filled with IDs) would work.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: efficient way of checking duplicates

    Hashes or trees are also a good way to check for duplicates or even "closeness", where-as hashes are an exact check.

    Hashes/trees are O(log(n)), hashes are O(1) (for the average search).

Similar Threads

  1. What is the fastest and most memory-efficient data structure?
    By aussiemcgr in forum Collections and Generics
    Replies: 5
    Last Post: October 11th, 2012, 03:48 PM
  2. What is the fastest and most efficient for 3 dimensional structures?
    By aussiemcgr in forum Collections and Generics
    Replies: 10
    Last Post: December 11th, 2010, 06:50 PM
  3. Check for duplicates before inserting into database
    By igor0203 in forum JDBC & Databases
    Replies: 1
    Last Post: December 2nd, 2010, 08:04 AM
  4. treemap Duplicates
    By debug in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 6th, 2010, 10:52 AM
  5. Replies: 1
    Last Post: March 28th, 2009, 07:21 AM

Tags for this Thread