473,549 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count the no. of duplicates in an array

2 New Member
I need to find the no. of duplicates in this array. There is something wong in the loop, can anyone please look at it and point me towards right direction.

Thanks

public class duplicate {
int temp, true_count;
int ar[] = { 1, 2, 3, 4, 1 };
int count;

public void find() {
for (int i = 0; i < ar.length - 1; i++) {
temp = ar[i];
for (int j = i; j <= ar.length-1 ; j++) {

if (temp == ar[j]) {

count += 1;
}

}


}
}

public static void main(String args[]) {
duplicate dup = new duplicate();
dup.find();

System.out.prin tln("The No of duplicates is :" + dup.count);

}

}
Sep 4 '09 #1
3 15399
r035198x
13,262 MVP
Are you in the same class with this guy?
Sep 4 '09 #2
squalled
2 New Member
hey thanks for the reply. It is my post there. I could not see u there. btw I am trying to do it using hashmap
Sep 4 '09 #3
r035198x
13,262 MVP
Don't cross post questions all over the forums then.
It's very confusing and annoying for people trying to help.
Sep 4 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
7802
by: Michelle | last post by:
hi, i have created an array from recordset containing user names eg. (davidp, davidp, evenf, patricka, rebeccah) which i have sorted in alphabetical order, but i need to identify duplicates in this array and the number of times it has been duplicated. can someone help?
4
1658
by: Graham | last post by:
Can someone point me to an algorithm for sorting double precision values that is stable with duplicates? Thanks, Graham
1
651
by: steve smith | last post by:
Hi i just wanted to knw the quickest way, of obtaining a count of the number of words in a string? Also how could I then output these words to a file, with only one word on each line in file, in alphabetical order , the first letter of the word capitalised and with no duplicates? Any help would be much appreciated. Thanks
14
12949
by: ak | last post by:
Is it possible to find repeated(duplicate) element in an array in single loop ? AK
4
13952
by: Mokita | last post by:
Hello, I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script, where I want to eliminate the duplicates in an array (String). for (int k=0; k<myLength; k++){ boolean isthere=false; for (int l=0; l<sizeres; l++){ if (res.equals(my)){
2
4139
by: tuananh87vn | last post by:
Hi ! can anyone help me with the following topic: Find All Duplicates in a List of Numbers - Array implementation - -InitializeTree() -AddNode() -Add into this programs one function which counts all duplicates by using a binary search tree implemented as an array (note: set the array size to 5,000,000 or...
2
2114
by: chemlight | last post by:
I'm trying to figure out how to order an array based on the number of duplicates, and then remove all duplicates. This is my code right now: foreach($acID as $searchterms){ $results = mysql_query(SELECT * FROM table WHERE field LIKE '%$searchterms%') while($row = mysql_fetch_array($results)){
40
17945
by: kylie991 | last post by:
Hi I am stuck on checking if a 2D array has duplicates. I have to write a function to check if a column has duplicates and then another function to check if the rows have duplicates from a file. How would I go about this... I have the array reading a file correctly is it just the check for duplicates that I am stuck on... :)
3
25056
Thekid
by: Thekid | last post by:
I'm trying to figure out a way to find if there are duplicates in an array. My idea was to take the array as 'a' and make a second array as 'b' and remove the duplicates from 'b' using 'set' and then compare a to b. If they're different then it will print out 'duplicates found'. The problem is that even after trying different arrays, some with...
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.