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


目录
相关文章
|
SQL Java
解读JAVA处理排名问题-关于学生成绩排名及Collections中的sort方法与Comparable的使用
写一个项目真是存在很多的bug,修复的时间往往比开发所需要的时间更长,今天又出了一个bug,在这里记录一下,主要是针对系统中学生的成绩排名。
278 0
|
10月前
|
安全 架构师 Java
Java大厂面试高频:Collection 和 Collections 到底咋回答?
Java中的`Collection`和`Collections`是两个容易混淆的概念。`Collection`是集合框架的根接口,定义了集合的基本操作方法,如添加、删除等;而`Collections`是一个工具类,提供了操作集合的静态方法,如排序、查找、同步化等。简单来说,`Collection`关注数据结构,`Collections`则提供功能增强。通过小王的面试经历,我们可以更好地理解这两者的区别及其在实际开发中的应用。希望这篇文章能帮助你掌握这个经典面试题。
260 4
|
存储 安全 Java
java.util的Collections类
Collections 类位于 java.util 包下,提供了许多有用的对象和方法,来简化java中集合的创建、处理和多线程管理。掌握此类将非常有助于提升开发效率和维护代码的简洁性,同时对于程序的稳定性和安全性有大有帮助。
263 19
|
安全 Java API
【JAVA学习之路 | 进阶篇】Collections工具类
【JAVA学习之路 | 进阶篇】Collections工具类
|
存储 安全 Java
Java详解 : 单列集合 | 双列集合 | Collections类
Java详解 : 单列集合 | 双列集合 | Collections类
336 0
|
Java 数据库
JAVA8遍历tree
JAVA8遍历tree
|
XML Java 数据库连接
mybatis报错:java.lang.IllegalArgumentException: Mapped Statements collection does not contain
mybatis报错:java.lang.IllegalArgumentException: Mapped Statements collection does not contain
|
安全 算法 Java
Java Collections工具类:常用方法与技巧
Java Collections工具类:常用方法与技巧
254 0
|
存储 Java
从零开始学习 Java:简单易懂的入门指南之可变参数及Collections类(二十五)
从零开始学习 Java:简单易懂的入门指南之可变参数及Collections类(二十五)
|
存储 Java
【Java基础】Collections集合概述和使用、ArrayList集合存储学生并排序及斗地主案例
【Java基础】Collections集合概述和使用、ArrayList集合存储学生并排序及斗地主案例
144 0