Search code examples
javacollections

Why is there no direct implemention of Bag in java collection framework?


I can't figure out why JCF (Java Collection Framework) does't have a Bag implementation(to allow duplicates and not maintain order). Bag performance would be much better than current Collection implementations in JCF.

  • I know how to implement Bag in Java.
  • I know Bag is available in Apache commons.
  • I know there are other implementations that can be used as a Bag but there is so much work to do in other implementations compared to a Bag.

Why has the Java Collections framework not provided direct implementations like this?


Solution

  • Posting my comment as an answer since it answers this question best.

    From the bug report filed here :

    There isn't a lot of enthusiasm among the maintainers of the Collection framework to design and implement these interfaces/classes. I personally can't recall having needed one. It would be more likely that a popular package developed outside the JDK would be imported into the JDK after having proved its worth in the real world.

    The need for having support for Bags is valid today.

    Guava has support for it. Also GS-Collections.