In this Data structures tutorial we will learn what is Singly LinkedList in java with example, diagrams and program. We will learn how to implement your own Single LinkedList in java. We will learn how to insert and delete Employee object at first of Singly LinkedList in java. We will also learn complexity of inserting and deleting operations at first of Singly LinkedList in java. We will use generic implementation of LinkedList to achieve so.

Full Program/Example to insert and delete Employee object at first of Singly LinkedList in java >

class Employee {

private String id;

private String name;

/**

* Employee constructor

*/

public Employee(String id, String name) { // constructor

this.id = id;

this.name = name;

}

@Override

public String toString() {

return"Employee [id=" + id + ", name=" + name + "] ";

}

}

/**

*Exception to indicate that LinkedList is empty.

*/

classLinkedListEmptyExceptionextends RuntimeException{

public LinkedListEmptyException(){

super();

}

public LinkedListEmptyException(String message){

super(message);

}

}

/**

*Node class, which holds data and contains next which points to next Node.

So in this Data structures tutorial we learned what is Singly LinkedList in java with example, diagrams and program. We learned how to implement your own Single LinkedList in java. We learned how to insert and delete Employee object at first of Singly LinkedList in java. We also learned complexity of inserting and deleting operations at first of Singly LinkedList in java. We used generic implementation of LinkedList to achieve so.

Having any doubt? or you you liked the tutorial! Please comment in below section.