Hello people..! This is a special extension for my discussion on Graph Theory Basics. Here, I give you the code for implementing the Adjacency List in Java. Some of the features of this code are –

• The Adjacency List is an array of LinkedLists, where each element is a Pair<Integer, Integer>, from javafx.util.Pair. This pair stores two values, the destination vertex, (V2 in an edge V1 → V2) and the weight of the edge.
• addEdge() – Appends an edge startVertexendVertex with a certain weight. This is an O(1) Insertion.
• getNumberOfVertices() – Returns the number of vertices in the graph. This value does not change once the graph is created.
• getNumberOfEdgesFromVertex() – Returns the number of edges coming out from a vertex. Basically, it returns the length of the linked list associated with the vertex.
• getEdgesFromVertex() – Returns a LinkedList object of edges that come out of this vertex. Changes made to the object returned does not affect the encapsulated adjacency list.
• removeEdge() – Removes an edge coming out of startVertex. It expects an object of Pair<Integer, Integer> which corresponds to the edge to be removed. Returns a boolean value regarding whether there was any change made to the Collection.
```/*
* using Collections API
*
* Authored by,
* Vamsi Sangam.
*/

import java.util.Scanner;
import javafx.util.Pair;

// Constructor

for (int i = 0; i < adjacencyList.length; ++i) {
}
}

// Appends a new Edge to the linked list
public void addEdge(int startVertex, int endVertex, int weight) {
}

// Returns number of vertices
// Does not change for an object
public int getNumberOfVertices() {
}

// Returns number of outward edges from a vertex
public int getNumberOfEdgesFromVertex(int startVertex) {
}

// Returns a copy of the Linked List of outward edges from a vertex
public LinkedList< Pair<Integer, Integer> > getEdgesFromVertex(int startVertex) {

return edgeList;
}

int i = 0;

System.out.print("adjacencyList[" + i + "] -> ");

for (Pair<Integer, Integer> edge : list) {
System.out.print(edge.getKey() + "(" + edge.getValue() + ")");
}

++i;
System.out.println();
}
}

// Removes an edge and returns true if there
// was any change in the collection, else false
public boolean removeEdge(int startVertex, Pair<Integer, Integer> edge) {
}
}

class testGraph
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);

int vertices = s.nextInt();
int edges = s.nextInt();
int u, v, weight;

int i = 0;

while (i < edges) {
u = s.nextInt() - 1;
v = s.nextInt() - 1;
weight= s.nextInt();