OOP Terminology: “Container” & “Collection”

2019-04-23 10:37发布

Is the C++ term "Container" simply synonymous with the Java term "Collection" ?

2条回答
Evening l夕情丶
2楼-- · 2019-04-23 11:03

Yes.

Though, if I may speculate here, C++ term container better emphasizes ownership of contained items, as opposed to Java's collection, where there is no explicit memory ownership (due to garbage collection).

Items in a C++ container are destroyed when a container is destroyed (hence items are contained or owned), in Java items may continue to exist if a collection itself is garbage collected.

查看更多
贼婆χ
3楼-- · 2019-04-23 11:27

Container (wikipedia)
Collection (wikipedia)

If I understand correctly - usualy this difference is not significant.

When we talk about group of objects we say "collection of objects".
If we talk about data structure which contain group of objects we say container.

e.g.: std::vector< int > - collection of ints or container vector which contain ints.

查看更多
登录 后发表回答