wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Checking for unique values in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Checking for unique values in an array" Watch "Checking for unique values in an array" New topic
Author

Checking for unique values in an array

Madhusudhan GoturKaranam
Greenhorn

Joined: Dec 31, 2002
Posts: 4
Hi,

I have an array which can have dynamic values..Don't know count..
I have to check for uniqueness in that array..

For Example, Array A1 = [1,2,3,3,1]

Here, '3' and '1' is repeated. I should for unique values and giving message if its repeated.

Pls help me..
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Basically you need to make a second array. Using the number of the firxt array, you add one too it. You need to loop through the whole array.

count[Array1[i]]

use the length property to check the number of elements.

No I am not going to code it!
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Here is an idea - since you could use the numbers you going to store as array indexes.

so,

than you could use
for(var i in myArray){ ... }
to loop through array.
Or, you coul have 2 arrays - one for indexes and one for data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking for unique values in an array