Return true if the elements of an array do not contain one or the other
In JDK there's nothing, but with Guava you could do

List&lt;Integer&gt; list com.google.common.primitives.Ints.asList(nums);
return !(list.contains(1) &amp;&amp; list.contains(4));


Obviously, converting int[] to something like ArrayList&lt;Integer&gt; would be a performance disaster. Fortunately, there's nothing like this, instead there's a class implementing the List interface by accessing the primitive array. Bulk-methods like contains are optimized and lead to a simple loop with no boxing inside.



But seriously, feel free to stick with your loop, as there's not always such a trick available. What you could improve:


You need no xxxCount, a simple boolean containsXxx would do. But this is no problem, having the count may be useful sometimes.
You could use an early return. Whenever you find a 1, you can check if you have already a 4 and return false if so.




The only part I dislike is

if (oneCount &gt; 0 &amp;&amp; fourCount &gt; 0) {
    return false;
}
return true;


You surely mean

return oneCount == 0 || fourCount == 0;




If performance was very important (which it rarely is), I'd try this

int i = 0;
int missing;
for (; ; i++) {
    if (i == nums.length) {
        return true;
    } else if (num[i] == 1) {
        missing = 4;
        break;
    } else if (num[i] == 4) {
        missing = 1;
        break;
    }
}
for (; i &lt; nums.length; i++) {
    if (nums[i] == missing) {
        return false;
    }
}
return true;


But as you can see, it's terribly long and not very readable. When embedded in a real code it may also be slower (due to inlining limit or whatever).