472,960 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Checking for duplicates

I currently have two String variables I check to find if they are duplicates:

Expand|Select|Wrap|Line Numbers
  1. String str1 = "red";
  2. String str2 = "yellow";
  3. if (str1.equals(str2)){
  4.       System.out.println("Duplicate");
  5. }
  6. else{
  7.       System.out.println("Not duplicate");
  8. }
Since red is not the same as yellow it would show "Not Duplicate".

Now how would I check 10 variables to find out if any of them are duplicates?

Expand|Select|Wrap|Line Numbers
  1. String str1 = "red";
  2. String str2 = "yellow";
  3. String str3 = "green";
  4. String str4 = "blue";
  5. String str5 = "red";
  6. String str6 = "green";
  7. String str7 = "green";
  8. String str8 = "white";
  9. String str9 = "black";
  10. String str10 = "green";
In this example red and green have duplicates.

Please advise how I can do this?
Oct 28 '07 #1
2 1615
Ganon11
3,652 Expert 2GB
I would use a String Array and 2 nested for...loops to iterate through the array, checking for duplicate values.

If you have them stored as str1, str2, str3,...,strN, then only way you can check for multiples is with many, many if statements (somewhere close to N^2).
Oct 29 '07 #2
heat84
118 100+
Every colour can have a boolean representing it e.g isRed which is false before the string red is entered. When the string is entered, the flag is set to true and when someone enters the string any other time the flag will be set to true - if its true , then duplicate should be printed.
Nov 12 '07 #3

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

Similar topics

1
by: Spockie | last post by:
I do not use linkedlist stdlibrary, vector i make my own, but i have problems with one issue, and that is checking if there are duplicates in the middle of inputing information line 294 ...
1
by: keys4worship | last post by:
Situation: Day 1 Table contains 100 items of actions imported via FTP. One of the fields in the table can be updated to reflect an assigned unit code. Day 2 Actions that may be duplicates of...
5
by: Jermin | last post by:
Hi, I have a database composed of a single table composed of 2 columns, an auto-numbered ID column and a column which contains 30 million random numbers. All I want to Access to do is check the...
2
by: Rampar | last post by:
I have a basic mailing list. Right now I have to search for a name before I put it in to make sure I am not wasting my time and making duplicate entries. I want to have a way to see possible...
5
by: kevinjouco | last post by:
Hello Have searched the group for a solution to the following problem without success: Table 1 has Ref No (No Duplicates) & Min Max Value Fields ie Ref No 1 Min 1 Max 10 Ref No 2 Min 11 Max...
1
by: AndyB | last post by:
I have found a lot of material on removing duplicates from a list, but I am trying to find the most efficient way to just check for the existence of duplicates in a list. Here is the best I have...
7
by: raddrummer | last post by:
I have a main form that has combo boxes linked to a query that outputs the results of the query to text boxes on a subform. We have a job code (naming) convention here that assigns the first 2...
2
by: lostdawg | last post by:
Hi, I have a question regarding duplicate entries. Basically I have a simple database with a main table called contacts. This table has 2 fields, contactsid and contactsnum. The main form has a...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.