Finding duplicates in two sorted arrays
You are looking for values in a sorted array, first thing that comes to mind is binary search (improves to \$O(n \log n)\$). 

However because the values you look for are also sorted then you know that the next value will be after the value you found in the last iteration. Keep the index where you broke out of the inner loop and start there during the next iteration.

int innerIndex = 0;
for(int count = 0; count &lt; sorted1.length; count ++) {
      for(; innerIndex &lt; sorted2.length; innerIndex++) {
           if(sorted1[count] == sorted2[innerIndex]) {
                duplicates.add(sorted1[count]);
           } else if(sorted1[count] &lt; sorted2[innerIndex]) {
              break;
           }
       }    
 }


Otherwise you can pretend to merge the arrays. It's essentially the same algorithm but makes it clearer what is happening:

int index1 = 0, index2
while(index1 &lt; sorted1.length &amp;&amp; index2 &lt; sorted2.length){
    if(sorted1[index1] &lt; sorted2[index2]){
        index1++;
    }else if(sorted1[index1] &gt; sorted2[index2]){
        index2++;
    }else{
        duplicates.add(sorted1[index1]);
        index1++;
        index2++;
    }
}