There is indeed a graph class in Java. java.util.Graphs is a utility class for building and manipulating graphs. It provides a set of static methods for performing various operations on graphs, such as building them from scratch, adding edges, calculating vertex degrees, etc.
Here's a simple example of how to use the Graphs class to build a graph:
import java.util.Graphs;
// Create a new, empty graph
Graph<Integer, String> g = new Graph<>();
// Add some edges to the graph
g.addEdge(1, 2, "A");
g.addEdge(2, 3, "B");
g.addEdge(3, 4, "C");
// Print out the degree of vertex 2
System.out.println("Degree of vertex 2: " + Graphs.degreeOf(g, 2));
The output of this program would be:
Degree of vertex 2: 2
As you can see, the Graphs class provides a convenient way to perform various operations on graphs. If you need to work with graphs in your Java program, this is the class you should use.