What is Linked List?
1) LinkedList l=new LinkedList(); ----> creates an empty linked object
2) LinkedList l=new LinkedList(Collection c); ----> creates an equivalent linked list object for the given collection.
---> Usually we can use linked lists to develop stacks and queues.To provide support for these requirement linked list class defines the following specific methods::
- The underlying data structure is doubly linked list
- Insertion order is preserved
- Duplicate objects are allowed
- Heterogeneous objects are allowed
- null insertion is possible
- Linked list implements Serializable and cloneable interfaces but not random access
- A linked list is the best choice if the ever frequent operation is insertion or deletion in the middle
- A linked list is the worst choice if the ever frequent operation is retrieval operation
1) LinkedList l=new LinkedList(); ----> creates an empty linked object
2) LinkedList l=new LinkedList(Collection c); ----> creates an equivalent linked list object for the given collection.
---> Usually we can use linked lists to develop stacks and queues.To provide support for these requirement linked list class defines the following specific methods::
- void addFirst(Object o)
- void addLast(Object o)
- Object getFirst()
- Object getLast()
- Object removeFirst()
- Object removeLast()
- LinkedList is the best choice if ever frequent operation is insertion/deletion in the middle
- LinkedList is the worst choice if ever frequent operation is retrieval operation
- In LinkedList, the elements won't be stored in consecutive memory locations and hence retrieval operation will become difficult
No comments:
Post a Comment
Please comment below to feedback or ask questions.