public static HashSet doHashSetSearchGreatestint numItems S
public static HashSet<Integer> doHashSetSearchGreatest(int numItems) {
System.out.print(\"doHashSetSearchGreatest: \");
HashSet<Integer> set = new HashSet<>();
// TODO Write code that adds integers 0 through (numItems - 1)
// to set.
long startTime = getTimestamp();
// TODO Write code that checks if integer (numItems - 1)
// is a member of set.
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return set;
}
Solution
HI, Please find my implementation.
To add: use add method
To search: use contains method
public static HashSet<Integer> doHashSetSearchGreatest(int numItems) {
System.out.print(\"doHashSetSearchGreatest: \");
HashSet<Integer> set = new HashSet<>();
// TODO Write code that adds integers 0 through (numItems - 1)
// to set.
for(int i=0; i<numItems; i++)
set.add(i);
long startTime = getTimestamp();
//long startTime = System.currentTimeMillis();
// TODO Write code that checks if integer (numItems - 1)
// is a member of set.
if(set.contains(numItems-1))
System.out.println((numItems-1)+ \" is a memeber of set\");
else
System.out.println((numItems-1)+ \" is not a memeber of set\");
long endTime = getTimestamp();
//long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return set;
}

