LinkedList element() Method in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 removing it. Java // Demonstrate element() method // for Integer value import java.util.LinkedList; class Geeks { public static void main(String[] args) { LinkedList<Integer> l = new LinkedList<>(); // Use add() to insert // elements in the list l.add(10); l.add(20); l.add(30); System.out.println("" + l); // getting the head of list // using element() method System.out.println("" + l.element()); } } Output[10, 20, 30] 10 Syntax of Java LinkedList element() Methodpublic E element()Return Value: This method returns the head of the list.Example 2: Here, element() method throws NoSuchElementException when we try to get the head of an empty LinkedList. Java // Throws Exception import java.util.LinkedList; import java.util.NoSuchElementException; class Geeks { public static void main(String[] args) { LinkedList<String> l = new LinkedList<>(); l.add("A"); l.add("B"); l.add("C"); System.out.println("" + l); // Displaying the head of List System.out.println("Head: " + l.element()); // Remove all elements // from the List l.clear(); try { // Try to get the head of // an empty LinkedList System.out.println( "Head of an Empty Linked List: " + l.element()); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output[A, B, C] Head: A Exception: java.util.NoSuchElementException Comment More info R rohitprasad3 Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions java-LinkedList +1 More Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readAccess Modifiers in Java6 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like