Why doesn't the Java Collections API include a Graph implementation?

Posted by dvanaria on Stack Overflow See other posts from Stack Overflow or by dvanaria
Published on 2010-06-05T22:43:24Z Indexed on 2010/06/05 22:52 UTC
Read the original article Hit count: 248

Filed under:
|
|
|

I’m currently learning the Java Collections API and feel I have a good understanding of the basics, but I’ve never understood why this standard API doesn’t include a Graph implementation. The three base classes are easily understandable (List, Set, and Map) and all their implementations in the API are mostly straightforward and consistent.

Considering how often graphs come up as a potential way to model a given problem, this just doesn’t make sense to me (it’s possible it does exist in the API and I’m not looking in the right place of course). Steve Yegge suggests in one of his blog posts that a programmer should consider graphs first when attacking a problem, and if the problem domain doesn’t fit naturally into this data structure, only then consider the alternative structures.

My first guess is that there is no universal way to represent graphs, or that their interfaces may not be generic enough for an API implementation to be useful? But if you strip down a graph to its basic components (vertices and a set of edges that connect some or all of the vertices) and consider the ways that graphs are commonly constructed (methods like addVertex(v) and insertEdge(v1, v2)) it seems that a generic Graph implementation would be possible and useful.

Thanks for helping me understand this better.

© Stack Overflow or respective owner

Related posts about java

Related posts about api