Counting pairs that have a given difference in Java
From a review of your code, I see that you loop over your input in a nested for loop. This is actually not required to solve the problem. Instead, create one hashset for every number in your numbers array, and another hashset for every number in numbers + k. Then we only have to check for intersections. 

This should take your \$O(n^2)\$ algorithm and turn it into a nicer \$O(n)\$. Here's my suggested code (note that I included an inner class to store the pairs, but you could use builtins to solve it too: 

private static class Pair {
    public int a;
    public int b;
    public Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public String toString() {
        return "("+a+","+b+")";
    }
}

public static List&lt;Pair&gt; getPairsFast(int k, List&lt;Integer&gt; numbers) {
    HashSet&lt;Integer&gt; hLow = new HashSet&lt;&gt;();
    HashSet&lt;Integer&gt; hHigh = new HashSet&lt;&gt;();
    List&lt;Pair&gt; ret = new ArrayList&lt;&gt;();
    for (int i : numbers) {
        hLow.add(i);
        hHigh.add(i+k);
    }
    for (int i : hHigh) {
        if (hLow.contains(i)) {
            ret.add(new Pair(i-k, i));
        }
    }
    return ret;
}


From some testing, it indeed seems to perform better the larger the input is, and it is >400 times faster for an input of size \$10^5\$.