LinkedList getFirst() Method in Java Last Updated : 08 Apr, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Linked List 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 Java.util.LinkedList.getFirst() method is used to fetch or retrieve the first element from a LinkedList or the element present at the head of the List. Illustration: Input : 4 --> 1 --> 5 --> 6 --> 1 --> 3 Output: 4 As we all know that getFirst() is one of the methods been there up present inside LinkedList class. It retrieves the first element from the object inside which elements of LinkedList are present. As we know LinkedList is a class been present inside java.util package so and if we do operate the following methods the syntax will look like as shown below as follows: import java.util.LinkedList; LinkedList ll = new LinkedList<T>(); ll.getFirst(); In simpler words, if we want to know the first element then do perform the below check as listed below. It will, later on, be illustrated as an example while implementing. Syntax: LinkedList.getFirst(); Return Value: The first element or the element at the head of the list. Example: Java // Java Program to Illustrate getFirst() Method // of LinkedList class // Importing required classes import java.io.*; import java.util.LinkedList; // Main class public class GFG { // Main driver method public static void main(String args[]) { // Creating an empty LinkedList by creating its // object Declaring object of type strings LinkedList<String> list = new LinkedList<String>(); // Adding custom input elements to the List // Using add() method list.add("Geeks"); list.add("for"); list.add("Geeks"); list.add("10"); list.add("20"); // Displaying the list(all elements inside object) System.out.println("LinkedList:" + list); // Fetching first element from the list // using getFirst() method System.out.println("The first element is: " + list.getFirst()); } } Output: LinkedList:[Geeks, for, Geeks, 10, 20] The first element is: Geeks Comment More infoAdvertise with us Next Article LinkedList getFirst() Method in Java C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections java-LinkedList Practice Tags : JavaJava-CollectionsMisc Similar Reads LinkedList getLast() Method in Java In Java, the getLast() method in the LinkedList class is used to retrieve the last element of the list.Example 1: Here, we use the getLast() method to retrieve the last element of the list.Java// Java Program to Demonstrate the // use of getLast() in LinkedList import java.util.LinkedList; public cl 2 min read LinkedList get() Method in Java In Java, the get() method of LinkedList is used to fetch or retrieve an element at a specific index from a LinkedList.Example 1: Here, we use the get() method to retrieve an element at a specified index.Java// Java Program to illustrate get() method import java.util.LinkedList; public class Geeks { 2 min read LinkedList addFirst() Method in Java In Java, the addFirst() method of LinkedList, adds elements at the beginning of the list. All the existing elements moved one position to the right and the new element is placed at the beginning.Syntax of LinkedList addFirst() Method public void addFirst( E e)Parameters: E is the data type of elemen 1 min read LinkedList element() Method in Java In Java, the element() method of the LinkedList class is used to retrieve the first element in the list without removing it. The first element of the LinkedList is known as the head. Example 1: Here, we use the element() method to retrieve the first element of the LinkedList of Integers, without rem 2 min read LinkedList addLast() Method in Java In Java, the addLast() method of the LinkedList class is used to add an element at the end of the list.Syntax of LinkedList addLast() Method void addLast( E e)Parameter: e is the element you want to add at the end of the list.Return type: This method does not return any value.Example: Here, we use t 1 min read Like