Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashSet use only key #68

Open
IvanAgafonov opened this issue Mar 28, 2021 · 0 comments
Open

HashSet use only key #68

IvanAgafonov opened this issue Mar 28, 2021 · 0 comments

Comments

@IvanAgafonov
Copy link

Неверно - "В качестве ключа и значения используется добавляемый элемент.". HashSet использует добавляемый элемент только в качестве ключа, а значение - объект Object.

private static final Object PRESENT = new Object();
public boolean add(E e) {
    return map.put(e, PRESENT)==null;
}

https://github.com/enhorse/java-interview/blob/master/jcf.md#%D0%BD%D0%B0%D0%B7%D0%BE%D0%B2%D0%B8%D1%82%D0%B5-%D0%BE%D1%81%D0%BD%D0%BE%D0%B2%D0%BD%D1%8B%D0%B5-%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D1%8B-jcf-%D0%B8-%D0%B8%D1%85-%D1%80%D0%B5%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D0%B8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant