Prim's algorithm via Priority Queues to print the minimum spanning tree of an undirected graph Here's my attempt, I believe the runtime is O(V*(ElogE + log E)) since the while loop runs V times and it takes ElogE + log E to do the priority queue operations inside the loop.
class Edge implements Comparable&lt;Edge&gt; {
  T source;
  T destination;
  int weight;

  public Edge(T source, T destination, int weight) {
     this.source = source;
     this.destination = destination;
     this.weight = weight;
  }

  public int compareTo(Edge other) {
    return this.weight - other.weight;
    }
}

public void printMSTPrims(Map&lt;T, List&lt;Edge&gt; &gt; adjacencyList) {
        // Records all visited destinations.
        Set&lt;T&gt; visited = new HashSet&lt;&gt;();
        Queue&lt;Edge&gt; edges = new PriorityQueue&lt;&gt;();
        T currentNode = adjacencyList.entrySet().iterator().next().getKey();
        visited.add(currentNode);
        // Run until we've visited all vertices
        while (visited.size() &lt; adjacencyList.size()) {
            
            // Take all edges from current node and add to the PQ.
            for (Edge edge: adjacencyList.get(currentNode)) {
                edges.add(edge);
            }

            // Pick the smallest edge to a destination node not already visited.
            Edge edge = edges.remove();
            while (!edges.isEmpty() &amp;&amp; visited.contains(edge.destination)) {
                edge = edges.remove();
            }

            // Found an eligible edge, print its contents. This edge does not have to necessarily start from the currentNode.
            System.out.println(edge.source + &quot;--&quot; + edge.weight + &quot;--&quot; + edge.destination);
            // Go next to this destination vertex.
            currentNode = edge.destination;

            //Now that you've reached this edge as a destination, record it.
            visited.add(currentNode);
        }

}

PS. I assume the graph does not have self-loops and double-edges.
For who is not familiar with Prim's algorithm: it finds a minimum spanning tree for a weighted undirected graph.

My suggestions:

Generics: the class Edge should be declared as Edge&lt;T&gt; or it won't compile as is. Or is it an inner class? Also the generic is missing in Comparable and the method compareTo.
compareTo: typically, for primitive types is better to use &lt;,&gt;, and return -1,0 or 1. In your case, compareTo could overflow the integer with a negative weight. You can change it from:
public int compareTo(Edge other) {
  return this.weight - other.weight;
}

To:
public int compareTo(Edge other) {
  return Integer.compare(this.weight,other.weight);
}


addAll instead of for-loop: adding all edges to the queue can be done with addAll. From:
for (Edge edge: adjacencyList.get(currentNode)) {
    edges.add(edge);
}

To:
edges.addAll(adjacencyList.get(currentNode));


Testing: the method printMSTPrims is hard to test. Would be better to have a method mstPrims that returns a result and then print it with another method. In that case, would be easier to test mstPrims.
Naming: the name edges is a bit generic, an alternative can be edgeQueue or just queue.

Your final assumption:

PS. I assume the graph does not have loops and self-edges.

So a tree? A (connected) acyclic undirected graph is a tree. Anyway, looking at your method I don't think there should be problems even if there are cycles.