# Program: Check if given Linked List is a Circular Linked List or not.

 Problem Description: Write a program to check given singly linked list is a circular linked list or not. Circular linked list is a sequence of elements in which every element has link to its next element in the sequence and the last element has a link to the first element in the sequence. Algorithm: Traverse from head node. Compare the current node with its next node. If the data of the next node is same as current nodes data, then delete the next node. Update current nodes next pointer to next nodes next value.

 IsCircularLinkedList ```package com.java2novice.algos; public class IsCircularLinkedList { static class Node { int data; Node next; Node(int tmp) {data = tmp;} } static boolean isCircularLinkedList(Node head) { if(head == null) { return Boolean.FALSE; } Node temp = head; do { temp = temp.next; } while(temp != null && temp != head); return (temp == head); } public static void main(String[] a){ Node n1 = new Node(34); Node n2 = new Node(25); Node n3 = new Node(31); Node n4 = new Node(56); Node n5 = new Node(45); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n1; System.out.println("Is it circular linked list: "+isCircularLinkedList(n1)); } } ```

 Output: `Is it circular linked list: true`

#### List Of All Interview Programs:

Knowledge Centre
String Vs StringBuffer
We know that String is immutable object. We can not change the value of a String object once it is initiated. If we try to change the value of the existing String object then it creates new object rather than changing the value of the existing object. So incase, we are going to do more modificatios on String, then use StringBuffer. StringBuffer updates the existing objects value, rather creating new object.
Famous Quotations
It’s not that I’m so smart, it’s just that I stay with problems longer.
-- Albert Einstein