Why Java Collections Framework does not contain Tree and Graph

简介: Why Java Collections Framework does not contain Tree and Graph

Why Java Collections Framework does not contain Tree and Graph

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


目录
相关文章
|
10月前
|
SQL Java
解读JAVA处理排名问题-关于学生成绩排名及Collections中的sort方法与Comparable的使用
写一个项目真是存在很多的bug,修复的时间往往比开发所需要的时间更长,今天又出了一个bug,在这里记录一下,主要是针对系统中学生的成绩排名。
105 0
|
30天前
|
安全 Java API
【JAVA学习之路 | 进阶篇】Collections工具类
【JAVA学习之路 | 进阶篇】Collections工具类
|
1月前
|
Java 数据库
JAVA8遍历tree
JAVA8遍历tree
|
1月前
|
XML Java 数据库连接
mybatis报错:java.lang.IllegalArgumentException: Mapped Statements collection does not contain
mybatis报错:java.lang.IllegalArgumentException: Mapped Statements collection does not contain
59 0
|
1月前
|
安全 算法 Java
Java Collections工具类:常用方法与技巧
Java Collections工具类:常用方法与技巧
|
1月前
|
存储 Java
从零开始学习 Java:简单易懂的入门指南之可变参数及Collections类(二十五)
从零开始学习 Java:简单易懂的入门指南之可变参数及Collections类(二十五)
|
1月前
|
存储 Java
【Java基础】Collections集合概述和使用、ArrayList集合存储学生并排序及斗地主案例
【Java基础】Collections集合概述和使用、ArrayList集合存储学生并排序及斗地主案例
45 0
|
1月前
|
存储 算法 Java
java数据结构,列举并解释Java中的集合框架(Collection Framework)。
java数据结构,列举并解释Java中的集合框架(Collection Framework)。
31 0
|
1月前
|
Java
Java之Collections的综合小练习
3. 综合练习 练习1:随机点名器 需求:班级里有N个学生,实现随机点名器
30 0
|
1月前
|
存储 Java
Java之可变参数和Collections的详细解析
1. 可变参数 在JDK1.5之后,如果我们定义一个方法需要接受多个参数,并且多个参数类型一致,我们可以对其简化. 格式: 修饰符 返回值类型 方法名(参数类型... 形参名){ } 底层:
33 0