What is meant by the term “bag”? [closed]

你说的曾经没有我的故事 提交于 2019-12-08 14:17:48

问题


What is a "bag" in Java? I tried to find out from Google but I could not find a precise answer. I got idea from what I found on google that bags are similar to multisets. I want to know whether I am right or wrong because I didnt get proper answer through searching on google.


回答1:


Bag: Collection without order, may contain duplicates. The same as multiset:

In mathematics, the notion of multiset (or bag) is a generalization of the notion of set in which members are allowed to appear more than once.

from Wikipedia.

Note that duplicate is based on the equals( method in most JRE libraries.




回答2:


Core java contains no Bag class though the Collections interface does have this to say:

Bags or multisets (unordered collections that may contain duplicate elements) should implement this interface directly. (http://docs.oracle.com/javase/6/docs/api/java/util/Collection.html)

Other libraries such as Apache Commons Collections may contain implementations named Bag and Guava has Multisets.



来源:https://stackoverflow.com/questions/18028838/what-is-meant-by-the-term-bag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!