File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Checking for unique values in an array

Madhusudhan GoturKaranam

Joined: Dec 31, 2002
Posts: 4

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

Joined: Nov 08, 2001
Posts: 15385
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.


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.


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:
subject: Checking for unique values in an array
It's not a secret anymore!