Check if a linked list is circular

Problem: For a given linked list, check if it is a circular linked list or not.

Problem Explanation: Circular linked list is the typical linked list in which the last Node will have it’s next point to the Head of the List. For a given linked list 10->20, 20->30, 30->10, where 10, 20 and 30 are addresses of nodes,  it is a circular linked list. Hence output is true.

Java Implementation

public class CircularLL {
public boolean isCircular(Node node) {
Node first = node, second = node;

while (first != null && first.getLink() != null && second.getLink() != null && second.getLink().getLink() != null) {
if (first.hashCode() == second.hashCode()) {
return true;
}
}

return false;
}

public static void main(String[] args) {
Node node1 = new Node(1, null);
Node node2 = new Node(2, node1);
Node node3 = new Node(3, node2);

CircularLL circularLL = new CircularLL();
System.out.println(circularLL.isCircular(node3));
}
}

public class Node {
private int value;

public Node(int value, Node n) {
this.value = value;
}

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}

public Node getLink() {