Q:

What can I use instead of Set() in Java?

The following code is in JavaScript to check if a pair of numbers in a set are equal to a specific sum.
function hasPairWithSum2(arr, sum){
    const mySet = new Set();
    const len = arr.length;

    for (let i = 0; i < len; i++){
        if (mySet.has(arr[i]))
            return true;

        mySet.add(sum - arr[i]);
    }

    return false;
}

How can I do the same in Java? What is the alternative to Set()?

A:

You can use below code which uses HashSet() in Java. 
public static boolean hasPairWithSum2(int arr[], int sum){
    HashSet<Integer>mySet=new HashSet<Integer>();
    int len = arr.length;

    for (int i = 0; i < len; i++){
        if (mySet.contains(arr[i]))
            return true;

        mySet.add(sum - arr[i]);
    }

    return false;
}

