What does the method getLast() do in java?

Java 8Object Oriented ProgrammingProgramming

<html><body><p>The <strong>getLast()</strong> method of the class<strong>&nbsp;java.util.LinkedList</strong> returns the last element in this list.</p><p><strong>Example:</strong></p><pre>import java.util.*; public class LinkedListDemo { &nbsp; &nbsp;public static void main(String[] args) { &nbsp; &nbsp; &nbsp; LinkedList list = new LinkedList(); &nbsp; &nbsp; &nbsp; list.add("Hello"); &nbsp; &nbsp; &nbsp; list.add(2); &nbsp; &nbsp; &nbsp; list.add("Chocolate"); &nbsp; &nbsp; &nbsp; list.add("10"); &nbsp; &nbsp; &nbsp; System.out.println("LinkedList:" + list); &nbsp; &nbsp; &nbsp; System.out.println("Last Element :" + list.getLast()); &nbsp; &nbsp;} }</pre><p><strong>Output:</strong></p><pre>LinkedList:[Hello, 2, Chocolate, 10] Last Element :10</pre></body></html>
raja
Updated on 30-Jul-2019 22:30:21

Advertisements