Results 1 to 3 of 3
  1. #1
    revathi17 is offline Member
    Join Date
    Aug 2007
    Rep Power

    Default Unique element in an array

    Hello there,

    Given an array int a[] = {10,11,12,13,10,11}. I want to print out the unique elements and the count of duplicates in this array.

    Can someone help me find this. I am kind of stuck in the logic.


  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    NewEngland, US
    Rep Power


    Some psuedo...
    Java Code:
    1) read the array and have method available for searching the array
      a) if a number matches any other number
         - mark it for non-printable
         - increase the counter
    2) Output the printable number and the counter
    I suspect there are quite a few classes you may be able to use for your operations if the specifications of your program are not limited to just a regular array. ArrayList comes to mind.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power


    You can use the Set (HashSet) class to remove the duplicate items in the array.

    1. Create an array
    2. Convert it to a List
    3. Create a Set from the List
    4. When you get the set, convert it back to array.

    After the step you'll have the duplicate element removed from the list.

Similar Threads

  1. How to use Idref Element and its advantages
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 10:04 AM
  2. Max element in an Array
    By mew in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 05:26 PM
  3. How to use Idref Element and its advantages
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:37 PM
  4. a no such element exception
    By headlice1 in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:36 PM
  5. Replies: 4
    Last Post: 07-31-2007, 05:19 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