Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”
Java Program to Access elements from a LinkedList.
Write a Java Program to Access elements from a LinkedList.
PROGRAM: Java Program to Access elements from a LinkedList.
/*Java Program to Access elements from a LinkedList.*/
1: Access elements from a linkedlist
import java.util.LinkedList;
class Main {
public static void main(String[] args) {
LinkedList<String> languages = new LinkedList<>();
// add elements in the LinkedList
languages.add(“Python”);
languages.add(“Java”);
languages.add(“JavaScript”);
System.out.println(“LinkedList: ” + languages);
// get the element from the LinkedList
String str = languages.get(1);
System.out.print(“Element at index 1: ” + str);
}
}