-2

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.

Alok
  • 7,734
  • 8
  • 55
  • 100
  • 6
    "Google wasn't helpful." - I find that hard to believe. – Mitch Wheat Aug 03 '13 at 03:04
  • 1
    my question has edited so I was not mean that – Alok Aug 03 '13 at 03:07
  • You mean, other than there's no such thing in Java? – Brian Roach Aug 03 '13 at 03:08
  • @AlokSinghMahor - What you originally wrote was *"I tried to find out from google but I could not find out precise answer."*. That is also hard to believe ... except in the sense that Google doesn't provide "answers" at all. (It provides search results that you have to read ...) – Stephen C Aug 03 '13 at 03:10
  • @StephenC-- I read the google results thats why I wrote that I am feeling bags are same as multisets – Alok Aug 03 '13 at 03:14
  • 1
    What makes you think that the search results you found were not a "precise answer"? – Stephen C Aug 03 '13 at 03:15
  • i didnt find any definition or precise quote in google results on what bags are in java. by reading those partial information I got idea that bags must be something similar to multiset. I wanted to know properly what bags are so I posted here. because I can get precise answers/definition or more relevant than what i read on google results. if I had got precise information in google results I would have not posted here. – Alok Aug 03 '13 at 03:29
  • Its popular to think that google has all answers. Google is a search engine..a good one but its got a rep of delivering the impossible. Refine your search, its not an oracle. Google has good solutions and some answers. Beyond the search engine, Google is adopting the Microsoft paradigm. "Our customers are our testers". This is apparent with every release they have...only to guise it as a competition "Tell us what you would do with X and we'll give you one early". Google is great..but they are not the pinnacle of excellence. They are the pinnacle of ideas..that's not to say they work well. – Slihp Aug 03 '13 at 05:28
  • @Slihp-- I know very well that google is just search engine that will just list up the search result based on my search query. so its upto only "search query", "content on all these sites which are crawlable by Google" and "some artificial intelligence integrated in google search engine". so of course google cant give all the answers so I posted my question here. – Alok Aug 03 '13 at 09:19

2 Answers2

2

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.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
1

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.

Benjamin Pack
  • 365
  • 2
  • 3