Sobes.tech
Junior — Middle

Have you had experience working with the LinkedList data structure?

sobes.tech AI

Answer from AI

LinkedList is a data structure representing a linked list, where each element contains a reference to the next (and in the case of a doubly linked list — to the previous) element. In Java, the class java.util.LinkedList implements a doubly linked list.

Main features of LinkedList:

  • Fast addition and removal of elements at the beginning and end of the list.
  • Slow access by index, as it requires sequential traversal of elements.

Example of using LinkedList in Java:

import java.util.LinkedList;

public class Example {
    public static void main(String[] args) {
        LinkedList<String> list = new LinkedList<>();
        list.add("First");
        list.add("Second");
        list.addFirst("Zero");

        for (String item : list) {
            System.out.println(item);
        }
    }
}