栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Why Java Collections Framework does not contain Tree and Graph

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Why Java Collections Framework does not contain Tree and Graph

Why Java Collections Framework does not contain Tree and Graph
  • Question Description
  • Answer

Question Description

I am familiar with Java Collection Framework which contains basic interfaces: Collection and Map. I am wondering why the Framework doesn’t contain structures as Tree and Graph which are basic collections. Both can be regarded as sub types of Collection.

By the way, I know TreeSet is implemented by Red-Black Tree underlying. However, the TreeSet is not a Tree but a Set, so there’s no real Tree in the framework.

Answer

This is a good question. I think it simply boils down to scoping. The core features that Collections API provides classes for are:

iteration order: Lists and sorted maps have specified iteration order, most sets don’t.

duplicates: Lists allow duplicates, sets do not

index: List values are indexed by integers, map values are indexed by other objects.

This gets us very far and I assume Joshua Bloch et al argued that more feature rich collections (graphs and trees which require internal relationship between elements, sets with multiplicity, bi-directional maps, …) can be implemented on top of these three core features, and are thus better off in libraries.

From # Stack Overflow

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/877716.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号