cupanTae
01-06-2006, 01:31 PM
Hi what i am having problems with arrays.
I have an array of, for now 10 string objects, and a second array containing the same objects. What i want to do is compare them and anywhere an object in the first array appears more than once in the second array i want to remove, it so that each object only occurs one time in the second array.
I have an idea how this could be done, take a for loop which iterates through all elements in the first array, and inside that a second loop that takes the first element of that array and compares it to each element in the second array, and so on for each element in the array. I just dont know how to implement this in java, or how to remove the duplicate entries from the second array, can anyone help it would be greatly appreciated!
Thanks
Just if this is any help, what i am doing at the moment is this:
for(int i = 0, n = words.length; i<n; i++) {
totalWords++;
for(int j = i+1, m = array1.length; j < m; j++){
if(words[i].equals(array1[j])){
System.out.println("match :" + words[i]);
Since i dont know how to remove an element from the array i have just been printing out where a duplicate word is found, however if a word appears more than 3 times in the array then it outputs "match" for that word an incorrect number of times... can anybody see why?
I have an array of, for now 10 string objects, and a second array containing the same objects. What i want to do is compare them and anywhere an object in the first array appears more than once in the second array i want to remove, it so that each object only occurs one time in the second array.
I have an idea how this could be done, take a for loop which iterates through all elements in the first array, and inside that a second loop that takes the first element of that array and compares it to each element in the second array, and so on for each element in the array. I just dont know how to implement this in java, or how to remove the duplicate entries from the second array, can anyone help it would be greatly appreciated!
Thanks
Just if this is any help, what i am doing at the moment is this:
for(int i = 0, n = words.length; i<n; i++) {
totalWords++;
for(int j = i+1, m = array1.length; j < m; j++){
if(words[i].equals(array1[j])){
System.out.println("match :" + words[i]);
Since i dont know how to remove an element from the array i have just been printing out where a duplicate word is found, however if a word appears more than 3 times in the array then it outputs "match" for that word an incorrect number of times... can anybody see why?