Can a MongoDB key have two arrays?

Comparing two java arrays???? anyone help?

  • heres the problem... my first array is Tim[] i type in its size(including the second array) and i inputted 4 elements....[1,2,2,4] the second array Moi[] consists of the elements[1,2,3,4] when i compare them regarding if they have equal elements or the same elements on both of the arrays...... when i print out the output in another array Joe[]....the output is this 1 2 2 4 i mean, how come there's two 2's???? is there any way to solve this?? i just want 1,2,4 to be displayed... am i missing something??? please help me out JavaAdicts.... thank you...

  • Answer:

    The reason you get two 2's is that Tim contains two 2's. Wrather than using an array to store the common numbers, use a set. Sets (i.e. TreeSet) do not allow duplicates: For example: int[] vals = {1, 2,2,4,5,5,6,6,6,6,6}; TreeSet<Integer> s = new TreeSet<Integer>(): for(int i : vals){ s.add(i); } for(int i : s){ System.out.println(i); } //WIll print out the followin numbers in no particular number: 1, 2, 4, 5, 6. Now, if you need the outputted values to be in sorted order, you can add a list to the mix: int[] vals = {1, 2,2,4,5,5,6,6,6,6,6}; TreeSet<Integer> s = new TreeSet<Integer>(): for(int i : vals){ s.add(i); } LinkedList<Integer> list = new LinkedList<Integer>(); list.addAll(s); Collections.sort(list); for(int i : list){ System.out.println(i); } //WIll print the same numbers as above but you are guaranteed they will be in sorted order.

max g at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Well, i have got a running example for you. I hope you will find your answer here. http://www.java-examples.com/compare-two-java-int-arrays-example other links for good code java sites, http://www.java2s.com/Tutorial/Java/0040__Data-Type/CompareTwoJavaintArrays.htm

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.