Home » questions » Which collections class in java offers constant-time performance for the basic operations -add(), re

Which collections class in java offers constant-time performance for the basic operations -add(), re

2006-08-04 06:13:21, Category: Programming & Design
Which collections class in java offers constant-time performance for the basic operations -add(), remove(), contains(), and size() ? Four Hint : A) TreeSet B) HashSet C) BitSet D) None of these

Answers

  1. jsd115

    On 2006-08-04 07:41:37


    Conceptually, only a hash table has O(1) add, remove, contains, and size. Of the options you listed, this means the HashSet would be the only collection with constant-time performance. A TreeSet is O(log n) in all operations, except size which could be implemented in O(1). I'm unsure of the implementation for a BitSet.
  2. boris

    On 2006-08-04 10:09:40


    B) HashSet
  3. india_kakinada

    On 2006-08-04 06:23:34


    LinkesList,Treemap,hashtable are better