This is the defination of getWindowHandles function from RemoteWebDriver class.
public Set<String> getWindowHandles() {
Response response = execute(DriverCommand.GET_WINDOW_HANDLES);
Object value = response.getValue();
try {
List<String> returnedValues = (List<String>) value;
return new LinkedHashSet<>(returnedValues);
} catch (ClassCastException ex) {
throw new WebDriverException(
"Returned value cannot be converted to List<String>: " + value, ex);
}
}
As you can see, List<String> is covered to LinkedHashSet. Sometimes DriverCommand.GET_WINDOW_HANDLES might return blank values or duplicate values. By converting that into set, we can avoid that.
Hope that answerd your question.