New LinkedList created from an existing LinkedList Program Analysis } Output is - : LinkedList after adding objects = Īfter removing first element, LinkedList is = Īfter removing Last element, LinkedList is = Īfter removing element 2, LinkedList is = ("New LinkedList created from an existing LinkedList" + link2) ("After removing 2, LinkedList is = "+ link) ("After removing Last element, LinkedList is = "+ link) ("After removing first element, LinkedList is = "+ link) ("Linkedlist after adding objects = " + link) In this program, we have created a LinkedList to hold objects and we will add/remove some elements from this list and use it to initialize a new LinkedList. Returns a ListIterator to iterate over elements of an ArrayList.Ĭreating a LinkedList and displaying its features. Returns an Iterator to iterate over elements of an ArrayList. Returns an Object array containing all the elements of an ArrayList. Removes the first occurrence of an Object from the ArrayList, if it is present. Removes an element at a specified index in an ArrayList. Returns the element at the specified index in an ArrayList. Removes all of the elements from the ArrayList Returns the total number of elements in an ArrayList. Returns and removes the head(first) element of the LinkedList. Returns the head(first) element of the LinkedList, without removing it. Inserts the element e at the end of the LinkedList. Removes the last element of the LinkedList. Removes the first element of the LinkedList. Inserts the element e at the end of LinkedList. Inserts the element e at the beginning of the LinkedList. Inserts the element e at the end of an LinkedList. Some important methods of LinkedList class Methods Both of the LinkedList hold Integer objects. This constructor example creates a LinkedList arrL2 initialized with the elements of a LinkedList arrL1. LinkedList arrL2 = new LinkedList(arrL1) This constructor creates a LinkedList initialized with the elements of Collection c, with a condition, that Collection c holds similar type of objects as the type declared by the LinkedList. This constructor example creates an ArrayList to hold Integer objects. This constructor creates an empty LinkedList of a particular object type. LinkedList can be used to depict a first-in, first-out( FIFO) or last-in, first-out( LIFO) storage.Ĭonstructors of LinkedList: 1) LinkedList().LinkedList maintains an order in which elements are inserted in it.LinkedList allows storage of duplicate elements in it.first-in, first-out( FIFO) or last-in, first-out( LIFO) principle.Īs LinkedList class implements Deque interface, so LinkedList can also be used to depict a Deque or even a Stack(LIFO). So LinkedList can be used to represent a first-in, first-out( FIFO) Queue. As, LinkedList implements Deque interface, Queue stores and removes its elements based on a first-in, first-out( FIFO) principle.LinkedList Class LinkedList is a collection class that implements List, Deque and Queue Interfaces.
0 Comments
Leave a Reply. |