The idea of ββPatash seems the simplest. You can use Arrays.sort() to easily and efficiently sort the array.
If you really want a SEARCH, you are probably using one of the Arrays.binarysearch() methods. But they also require sorted arrays .... For each element of your array (say, by index n), find the 0 ... (n-1) section, and also search for the part (n + 1) ... (length - 1), but that would be extremely useless if you could just compare with one element adjacent to n. So, back to the previous sentence.
If you want to code a little bit, perhaps due to speed, you can use the contains() method of one of the implementing AbstractCollection classes - perhaps ArrayList (may contain duplicates), TreeSet (sorted, contains unique values) or HashSet (unsorted, contains unique values). You can call the constructor for these collections with the Arrays.asList(yourArray) parameter, so you do not need to fill one by one.
As ay89 rightly mentions, it's easier to have an array with unique values ββ(lots of other words), and then check to see if your value is set before trying to add it. Makes things a lot easier. But you may not always have that luxury with what is given to you.
source share