Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 08:01 AM
Member
 
Join Date: Aug 2007
Posts: 22
revathi17 is on a distinguished road
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.


Thanks,
-R
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-31-2007, 08:04 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Some psuedo...
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-31-2007, 10:44 AM
Senior Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 102
wsaryada is on a distinguished road
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.
__________________
Website:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use Idref Element and its advantages Java Tip Java Tips 0 03-30-2008 12:04 PM
Max element in an Array mew New To Java 5 12-03-2007 07:26 PM
How to use Idref Element and its advantages JavaBean Java Tips 0 09-26-2007 10:37 PM
a no such element exception headlice1 New To Java 1 08-07-2007 07:36 PM
selectSingleNode not returning element... schu777 XML 4 07-31-2007 07:19 PM


All times are GMT +3. The time now is 03:33 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org