Reputation: 1107
If set is a HashSet of integers..
HashSet<Integer> set = new HashSet<Integer>
What is the running time of the method .contains()
Example:
set.contains(int)
I am using Java 7.
Upvotes: 3
Views: 4878
Reputation: 886
The method contains
of the HashSet class in Java operates in constant time. I would also add that other basic operations, such as add
, remove
, and size
also operate in constant time.
Upvotes: 5