"Day 24: Learning Java Lists with Examples and Code"

🚀 Day 24 of 30 Days Java Challenge — List in Java 📃 Hello Connections 👋 Today I continued learning Java Collections, and the topic is List. 💡 What is a List in Java? A List is a Collection in Java that stores ordered elements. Key features: ✅ Maintains insertion order ✅ Allows duplicate values ✅ We can access elements using index (like arrays) 🧺 Real-life Example Think of a shopping list 📝 You write items in a specific order: 1. Milk 2. Bread 3. Eggs You may also repeat items (e.g., 2 Milk packets). This is how Java List works. 🧠 Different List Types in Java List Type Description ArrayList Fast, mostly used LinkedList Good for frequent adding/removing Vector Synchronized (rarely used now) We mostly use ArrayList in real projects. 🧩 Simple Code Example import java.util.*; public class Main { public static void main(String[] args) { List<String> names = new ArrayList<>(); names.add("Swetha"); names.add("Ravi"); names.add("Swetha"); // duplicate allowed System.out.println(names); System.out.println("First element: " + names.get(0)); } } 🟢 Output: [Swetha, Ravi, Swetha] First element: Swetha 🎯 Summary Feature List Order Yes ✅ Duplicates Allowed ✅ Index Access Yes #Java #Collections #ListInJava #ArrayList #CodingJourney #JavaForBeginners #30DaysChallenge #LearningEveryday

  • icon

To view or add a comment, sign in

Explore content categories