LinkedList is a part of the Collection framework present in java.util package. This class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using pointers and addresses. Each element is known as a node.
Input: l.put(2, 5); l.put(3, 6); l.put(4, 1); l.put(8, 2); Output: LinkedList of key-> [2, 3, 4, 8] LinkedList of values-> [5, 6, 1, 2] respectively the output for key and values.
Syntax of keySet() Method
Parameters: The method does not take any parameters.
Return Value: The method returns a set having the keys of the hash map.
Syntax of values() Method
Parameters: The method does not accept any parameters.
Return Value: The method is used to return a collection view containing all the values of the map.
List<Integer> list = new LinkedList<>(l.keySet()); List<Integer> listOfValue = new LinkedList<>(l.values());
LinkedList of key-> [2, 3, 4, 8] LinkedList of values-> [5, 6, 1, 2]
LinkedList of key-> [1, 3, 4] LinkedList of values-> [Geeks, Geeks, For]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.