473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to find the difference between two arrays?

Right, so I am trying to find the answer to the above question and then return it as type IntSet. For this question, I need to use arrayList. I have tried tweaking the code a number of times, however, the array contains the wrong elements. The intersection method called works perfectly fine, so the problem is not there. I think it is when I am trying to remove elements from the list that the problems start. Your help is much appreciated.

Expand|Select|Wrap|Line Numbers
  1.         public IntSet difference(Integer[] s1, Integer[] s2) {
  2.  
  3.         IntSet result = intersection(s1, s2);//get intersection array
  4.         IntSet s3;
  5.         Arrays.sort(s1);//sort arrays
  6.         ArrayList<Integer> difference = new ArrayList(Arrays.asList(s1));//creates new array
  7.         int[] s4 = new int[result.al.size()];
  8.         int counter = 0;
  9.         for (int int2 : result.al) {
  10.             s4[counter++] = int2;
  11.         }
  12.         for (int s : s4) {
  13.             if (difference.contains(s)) {
  14.                 difference.remove(s);
  15.             }
Nov 17 '12 #1
0 1951

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

Similar topics

2
by: AzGhanv/. | last post by:
Hi, I m searching for some Script / Function ... to find difference in data b/w 2 similar tables (exactly same fields structure) in sql 2000. plz update me asap ! thanks in advance !
1
by: bradleyc | last post by:
How would you calculate the difference between two dates?
1
by: Prafull Soni | last post by:
hi Can anyone give me program to find difference between two dates? thanks Prafull Soni
5
by: Ali Baba | last post by:
Hi, Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. Docs says that I can use TimeSpan like: TimeSpam ts =...
23
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that...
5
by: Konstantinos Pachopoulos | last post by:
Hi, does any body now any such algorith? to find difference in days from YYYYMMDD to YYYYMMDD? Or just an algorithm, that converts YYYYMMDD to seconds since the epoch? Thanks
2
by: raphael001 | last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
2
by: manishamca | last post by:
can anyone say me how to find the difference of values present in two textbox and display the result in the third textbox. for eg: <input type=text name=t1 value=123> <input...
1
rizwan6feb
by: rizwan6feb | last post by:
I am developing an application in VB.net 2005 that synchronizes two mysql databases of same structure. I have done most of the work but having problem in finding the difference in records in 2...
4
dlite922
by: dlite922 | last post by:
Short Version How do you find the difference between two database with the same structure but different data? with SQL (results will be ingested with PHP). Long Version Seems like a little...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.