What We Are Learn On This Post
How To Add Values Last LinkedList in Java With Example?
package com.java.Softwaretestingblog; import java.util.LinkedList; public class Add_Values_Last_LinkedList { public static void main(String[] args) { // TODO Auto-generated method stub //www.softwaretestingblog.in LinkedList<String> arrl = new LinkedList<String>(); arrl.add("First"); arrl.add("Second"); arrl.add("Third"); arrl.add("Random"); System.out.println(arrl); System.out.println("Adding element at last position..."); arrl.addLast("I am last"); System.out.println(arrl); System.out.println("Adding element at last position..."); arrl.offerLast("I am last - 1"); System.out.println(arrl); System.out.println("Adding element at last position..."); arrl.offer("I am last - 2"); System.out.println(arrl); } }
Read Also: Remove Spaces From Sentence In Java
Output:
[First, Second, Third, Random] Adding element at last position... [First, Second, Third, Random, I am last] Adding element at last position... [First, Second, Third, Random, I am last, I am last - 1] Adding element at last position... [First, Second, Third, Random, I am last, I am last - 1, I am last - 2]
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Leave a Reply