Will Zelan wrote:1)comparing two arrays and remove duplicates in java
k if we assingning two arrays
int array1[]={5,2,3,7};
int array2[]={5,1,2,6,7};
so i just initialize the two array with duplicate values
so how to compare them and remove duplicates how to implement them any ideas
Steve
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Steve Luke wrote:
Will Zelan wrote:1)comparing two arrays and remove duplicates in java
k if we assingning two arrays
int array1[]={5,2,3,7};
int array2[]={5,1,2,6,7};
so i just initialize the two array with duplicate values
so how to compare them and remove duplicates how to implement them any ideas
What have you tried? Do you know how to compare ints? Do you know how to access a single int that resides in the array?
Jeff Verdegan wrote:
Will Zelan wrote:anyone tell me whats the wrong declaring array which i have been post above
Post real code--an SSCCE(←click), and copy/paste the exact, complete error message.
Nobody has said that.Will Zelan wrote: . . . but some one saying its wrong to declare arrray in that manner, . . .
Campbell Ritchie wrote:
Nobody has said that.Will Zelan wrote: . . . but some one saying its wrong to declare arrray in that manner, . . .
Will Zelan wrote:i can able to compare the two arrays but i dnt have an idea how to remove duplicates in one array without using collections
Steve
Steve Luke wrote:
Will Zelan wrote:i can able to compare the two arrays but i dnt have an idea how to remove duplicates in one array without using collections
There is a key feature of the array which makes what you want to do difficult. Can you describe what an array is, and why that makes doing what you say above hard?
In the end, you will have to come up with a definition of what it means to 'remove duplicates' - what do you want to do with the non-duplicates. and what 'remove' actually means. But to understand that stuff you have to understand what an array is, by definition in Java, first.
Will Zelan wrote:array is nothing but more than one value can be stored,we can store the values in index based and we can retrieve the number by using for loop,then we will print the values
Steve
for example a array contains 5,4,2,3,1 and b array contains 5,4,8,9,7,so output will be a is 5 4 2 3 1 and b is 8 9 7
Steve
Steve Luke wrote:Just to point out why I am dwelling on this: You said:
for example a array contains 5,4,2,3,1 and b array contains 5,4,8,9,7,so output will be a is 5 4 2 3 1 and b is 8 9 7
That result is impossible to achieve. If you understand arrays you should understand why. You might also might come up with a suitable re-statement of the expected results so as to provide an achievable outcome.
Campbell Ritchie wrote:Because there is nothing else to say at the moment.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |