Java LinkedList — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 41 / 50 · தமிழ்

Java LinkedList

Explore a list that also works as a deque.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind LinkedList.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

LinkedList implements both List and Deque. End operations such as addFirst and removeFirst make its behavior easy to explore. It is not automatically faster than ArrayList for every insert or delete; traversal, memory use, and locality also matter.

02 / Step by step

விரிவான விளக்கங்கள்

Java LinkedList என்னன்னு தெரியுமா?

LinkedList-உம் ArrayList மாதிரியே ஆனா internally different-ஆ work ஆகும். ஒவ்வொரு element-உம் next element-ஐ point பண்றது.

LinkedList use பண்றதுக்கு:

ArrayList vs LinkedList

  • நிறைய data store பண்றதுக்கு ArrayList better
  • Frequent add/remove operations-க்கு LinkedList better
  • Random access (index-ல) ArrayList faster
  • Sequential access LinkedList efficient
Java reference fragmentJAVA
LinkedList<String> cars = new LinkedList<>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");

cars.addFirst("Mazda");
cars.addLast("Toyota");
cars.removeFirst();
cars.removeLast();

System.out.println(cars.getFirst()); // Volvo
System.out.println(cars.getLast());  // Ford
System.out.println(cars);            // [Volvo, BMW, Ford]

`LinkedList` எப்போது `ArrayList`-ஐ விட சிறந்தது?

  1. Random access (index) operations-க்கு
  2. Frequent insertions/deletions-க்கு, குறிப்பாக list-ன் நடுவில்
  3. Memory குறைவாக use செய்ய
  4. Sorting-க்கு
Reveal answer / விடை

Frequent insertions/deletions-க்கு, குறிப்பாக list-ன் நடுவில்

`LinkedList` middle insertions/deletions O(1) (node pointer change மட்டும்). `ArrayList` middle insert O(n) (shift required). ஆனால் random access-க்கு ArrayList O(1), LinkedList O(n).

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
import java.util.LinkedList;
public class Main {
    public static void main(String[] args) throws Exception {
        LinkedList<String> queue = new LinkedList<>();
        queue.addLast("Kavi");
        queue.addLast("Malar");
        queue.addFirst("Arun");
        System.out.println(queue.removeFirst());
        System.out.println(queue);
    }
}
Predict first. Then reveal the expected output / வெளியீடு
Arun
[Kavi, Malar]

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Use peekFirst before removeFirst and compare the list contents afterwards.

Reveal the answer and reasoning / விடை

peekFirst reads without removing; removeFirst reads and removes. For a general queue or stack, also consider ArrayDeque.

தவிர்க்க வேண்டிய தவறு: get(index) on LinkedList requires traversal. Do not assume constant-time random access.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.