🚀 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
"Day 24: Learning Java Lists with Examples and Code"
More Relevant Posts
-
Full Stack Java Development - Week 12 Update WEEK 12 – Java Collections (Part 2) Goal: Learn advanced Collection classes — Set, Map, Queue Day 56 – Set Interface & HashSet 📘 Topics: Set properties: no duplicates, no index HashSet internal working (HashMap-based) 💡 Sets in Java ensure uniqueness — perfect for student roll numbers or IDs! Day 57 – LinkedHashSet 📘 Topics: Maintains insertion order Difference between HashSet & LinkedHashSet 💡 LinkedHashSet combines uniqueness with order — like a to-do list with no duplicates! Day 58 – TreeSet 📘 Topics: Automatically sorted elements Uses TreeMap internally 💡 TreeSet in Java: stores unique elements in natural sorted order — ideal for ranking systems. Day 59 – Map Interface & HashMap 📘 Topics: Key-value pairs Important methods: put(), get(), keySet(), values(), entrySet() 💡 HashMap is one of the most used classes in Java! Learned how to store and retrieve data efficiently using key-value pairs. Day 60 – LinkedHashMap & TreeMap 📘 Topics: LinkedHashMap → maintains insertion order TreeMap → sorted order of keys 💡 Explored LinkedHashMap and TreeMap — order + sorting made easy #Codegnan #sakethKallepu sir #Java #Full stack java
To view or add a comment, sign in
-
Understanding the Set Interface in Java In Java, the Set interface is one of the most important parts of the Collections Framework. It is used when you want to store unique elements — that is, elements that should not be repeated. Unlike List, a Set does not maintain insertion order (except in a few implementations), and it does not allow duplicates. This makes it ideal for scenarios where uniqueness is important, such as maintaining a list of user IDs, email addresses, or registered students. Key Features of Set Does not allow duplicate elements Can contain at most one null element Does not maintain insertion order (depends on implementation) Provides efficient lookup and insertion operations Common Implementations of Set 1. HashSet Stores elements using a hash table. Does not maintain any order of elements. Provides constant-time performance for add, remove, and contains operations. 2. LinkedHashSet Maintains insertion order while still preventing duplicates. Slightly slower than HashSet but useful when order matters. 3. TreeSet Stores elements in sorted (ascending) order. Implements the NavigableSet interface and uses a Red-Black Tree internally. Example in Java import java.util.*; public class SetExample { public static void main(String[] args) { Set<String> fruits = new HashSet<>(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Mango"); fruits.add("Apple"); // duplicate ignored System.out.println("Fruits: " + fruits); } } Output: Fruits: [Banana, Apple, Mango] (Note: The order may vary because HashSet does not maintain insertion order.) When to Use Which Use HashSet when order doesn’t matter and performance is key. Use LinkedHashSet when you need to maintain insertion order. Use TreeSet when you want elements to be automatically sorted. Final Thought The Set interface is perfect when uniqueness is your priority. Whether you’re handling usernames, IDs, or any collection where duplicates aren’t allowed — Set helps maintain clean and efficient data. Mastering when and how to use different Set implementations can make your Java code more optimized and reliable. #Java #Collections #SetInterface #Programming #JavaDeveloper #SoftwareDevelopment #Learning #TechCommunity #SoftwareEngineer #WomenInTech #Coding
To view or add a comment, sign in
-
-
🚀 Java Date Fundamentals: Exploring the java.util.Date Class 📅 Today, I explored the foundational java.util.Date class in Java, which provides basic functionality for working with dates and times. While the modern recommendation is to use the java.time package (introduced in Java 8), understanding this original class is still important! 🔑 Key Methods Demonstrated Creation and Output: new Date(): Creates an object representing the current date and time. System.out.println(obj): Prints the date in a default, human-readable format. obj.getTime(): Returns the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 GMT). Accessing Date Components (Deprecated Methods): Methods like getDate(), getMonth(), getYear(), getHours(), etc., are available to retrieve individual components of the date. However, they are generally deprecated (outdated) because they are often confusing or not thread-safe. Comparison Methods: obj1.after(obj2): Returns true if obj1 represents a moment in time after obj2. obj1.before(obj2): Returns true if obj1 represents a moment in time before obj2. These methods are reliable for comparing two Date objects created from different points in time. 💡 The Modern Context The @SuppressWarnings("deprecation") warning in the code is a reminder that while these older methods work, the current best practice is to use the modern, much clearer, and immutable classes from the java.time package (like LocalDate, LocalTime, and Instant). This exercise was valuable for understanding the evolution of date handling in Java! Thank you sir Anand Kumar Buddarapu,Saketh Kallepu,Uppugundla Sairam,Codegnan #Java #Programming #DateHandling #JavaUtilities #SoftwareDevelopment #EclipseIDE #Codegnan
To view or add a comment, sign in
-
-
🚀 Day 19 of 30 Days Java Challenge — Java Exception Hierarchy 🌳 In the last post (Day 18), we learned about Exception Handling using try and catch blocks. But do you know how all exceptions are organized in Java? 🤔 Let’s understand the Exception Hierarchy today — it’s simpler than it looks! 😄 💡 What is Exception Hierarchy? In Java, all errors and exceptions are part of a tree-like structure called the Exception Hierarchy. At the top of this hierarchy is a class called Throwable. Every error or exception in Java comes from this class. 🧩 Structure Overview Object └── Throwable ├── Exception │ ├── IOException │ ├── SQLException │ ├── RuntimeException │ │ ├── ArithmeticException │ │ ├── NullPointerException │ │ └── ArrayIndexOutOfBoundsException │ └── ... └── Error ├── OutOfMemoryError ├── StackOverflowError └── ... 🟢 Key Points: Throwable → Parent of all exceptions and errors. Exception → Problems your program can handle. Error → Serious system problems you cannot handle (like memory issues). RuntimeException → Happens while your program runs (like divide by zero). Checked Exceptions → Checked at compile time (like IOException). 🌍 Real-life Example: Think of it like your family tree 👨👩👧👦 At the top, you have your grandparent (Throwable), then parents (Exception, Error), and finally, children (ArithmeticException, IOException, etc.) Each “child” inherits qualities from the “parent.” 🎯 Takeaway: Every exception belongs somewhere in this hierarchy. Knowing where each exception fits helps you decide how to handle it. It’s the foundation for mastering error handling in Java #Java #CodingChallenge #JavaBeginners #ExceptionHandling #JavaLearning #LearnJava #30DaysChallenge
To view or add a comment, sign in
-
-
🔗 Day 17: LinkedList in Java Today, I explored LinkedList in Java, an important data structure that allows dynamic insertion and deletion of elements efficiently. 💡 What I Learned Today LinkedList is part of the java.util package. It implements both List and Deque interfaces. Elements are stored as nodes, each linked to the next and previous ones. Fast insertion and deletion, slower random access compared to ArrayList. Can be used as List, Queue, or Deque. 🧩 Example Code import java.util.LinkedList; public class LinkedListDemo { public static void main(String[] args) { LinkedList<String> names = new LinkedList<>(); names.add("Raj"); names.add("Arun"); names.addFirst("Kumar"); names.addLast("Devi"); System.out.println("LinkedList: " + names); names.removeFirst(); names.removeLast(); System.out.println("After removal: " + names); } } ⚔️ Difference Between ArrayList and LinkedList ArrayList → Best for random access. LinkedList → Best for frequent insertions or deletions. 🗣️ LinkedIn Caption 🔗 Day 17 – Understanding LinkedList in Java Learned how LinkedList stores data in connected nodes and shines in insertion/deletion tasks. Also explored how it differs from ArrayList in speed and structure. Another key milestone in my #30DaysOfJava journey 🚀 #Java #CoreJava #LinkedList #LearnJava #Programming
To view or add a comment, sign in
-
-
Full Stack Java Development - Week 11 Update 🗓 WEEK 11 – Java Collections (Part 1) Goal: Understand legacy classes, cursors, and basic Collection types (Set, List, Stack, Vector) Day 51 – Vector and Stack 📘 Topics: Vector & Stack classes Examples (push, pop, peek) Difference between Vector & ArrayList 💡 I learned about legacy classes in Java: Vector and Stack. Stack follows LIFO order—just like a pile of plates! Day 52 – Important Methods in Stack 📘 Topics: push(), pop(), peek(), empty(), search() Real-life example: browser history / undo operation 💡 Explored Stack in Java — perfect example of LIFO (Last In, First Out)! Implemented a small undo feature using Stack. Day 53 – Cursors in Java 📘 Topics: Enumeration, Iterator, ListIterator Difference between them 💡 Learned how Java traverses collections using Cursors — from old-school Enumeration to the modern ListIterator. Day 54 – Enumeration Interface 📘 Topics: Methods: hasMoreElements(), nextElement() Works with legacy classes (Vector, Stack) 💡Enumeration — the oldest cursor in Java! Still useful when working with legacy code. Day 55 – ListIterator 📘 Topics: Methods: hasNext(), hasPrevious(), next(), previous() Traversing in both directions Bidirectional traversal made easy with ListIterator! It’s powerful when you need to move forward and backward through lists #Codegnan #sakethKallepu sir #Java #Full stack java
To view or add a comment, sign in
-
🧠 Java Basics Made Simple: Identifiers & Common Rules 🚀 Every Java beginner should know these simple but important rules 👇 1️⃣ Declare every identifier (variable, class, or method name) before using it. 2️⃣ Don’t use reserved words (like class, int, public) as identifiers. 3️⃣ Java is case-sensitive – Main and main are not the same! 4️⃣ Match quotes properly — char → single quotes 'A' String → double quotes "Hello" 5️⃣ Use only the correct apostrophe (') for char. 6️⃣ To use quotes inside strings → use escape characters: \" for double quote \' for single quote 7️⃣ Left side of = must be a variable, not a constant. 8️⃣ For String assignment, right side must be a string or string expression. 9️⃣ In concatenation (+), at least one operand should be a String. 🔟 Don’t forget your semicolon (;) at the end of each statement! 💾 File name rule: If your class is MyProgram, save it as MyProgram.java. 💬 Comments: Use /* comment */ properly — don’t forget to close it! 🧩 Braces {} and parentheses () must always be balanced. ⚙️ Objects: Use new to create an object — for example: Student s = new Student(); 🔹 Class vs Instance methods: Class method → ClassName.method() Instance method → objectName.method() ✅ The main() method must be public inside a public class. ✅ Add throws clause if your method uses readLine(). --- 💡 Simple rule: focus on small details — they make your Java code error-free! #Java #ProgrammingTips #CodingMadeSimple #LearnJava #Developers
To view or add a comment, sign in
-
🚀 Java Learning Update: Methods That Exist in LinkedList but NOT in ArrayList Today I explored one of the most interesting distinctions in Java Collections - the extra powers that LinkedList offers compared to ArrayList. Because LinkedList implements both List and Deque, it supports several special operations that ArrayList simply cannot. Here are the LinkedList - exclusive methods every Java developer should know 🔗 Methods for Adding Elements ➡️ addFirst() – Add an element at the beginning ➡️ addLast() – Add an element at the end ➡️ offer(), offerFirst(), offerLast() – Safer queue-style additions 🔍 Methods for Accessing Elements ➡️ getFirst() – Fetch the first element ➡️ getLast() – Fetch the last element ➡️ peek(), peekFirst(), peekLast() – Check elements without removing them 🧹 Methods for Removing Elements ➡️ removeFirst() – Remove first element ➡️ removeLast() – Remove last element ➡️ poll(), pollFirst(), pollLast() – Safe removals that return null when empty 📌 Stack-Specific Methods ➡️ push() – Insert like a stack ➡️ pop() – Remove like a stack #Java #JavaDeveloper #JavaLearning #CollectionsFramework #LinkedList #ArrayList
To view or add a comment, sign in
-
-
🚀 Day 17 of 30 Days Java Challenge — What is an Exception in Java? ⚡ 💡 What is an Exception? In Java, an Exception is an unexpected event that happens during the execution of a program, which disrupts the normal flow of instructions. In simple words — it’s Java’s way of saying, > “Something went wrong while running your program!” 😅 ⚠️ Example: public class Example { public static void main(String[] args) { int number = 10; int result = number / 0; // ❌ Division by zero System.out.println(result); } } 🧾 Output: Exception in thread "main" java.lang.ArithmeticException: / by zero Here, Java throws an ArithmeticException because dividing by zero is not allowed. When this happens, the program stops running unless handled (we’ll cover that later 😉). 🧩 Why Exceptions Exist They help detect and report errors during program execution. They make it easier to debug and maintain code. They prevent the entire program from behaving unpredictably when something goes wrong. 🌍 Real-world Analogy Think of an exception like an unexpected roadblock while driving 🚧. You’re going smoothly, but suddenly there’s construction ahead — your journey is interrupted. That interruption is what we call an exception in your program! 🎯 Key Points Exception = an unexpected event in a program. It disrupts the normal flow of code. Java notifies you by throwing an exception (like a signal). 💬 Quick Thought Have you ever seen an exception message and wondered what it really meant? 🤔 Share the most confusing one you’ve encountered below! 👇 #Java #CodingChallenge #JavaBeginners #LearnJava #Exceptions #JavaLearningJourney
To view or add a comment, sign in
-
-
💻 *Learning Update: Java Packages & Import Statements* I learned how to *organize and reuse Java code* efficiently using: ✅ *Packages* – Group related classes and interfaces for better code structure. ✅ *Built-in Packages* – Like `java.util`, `java.io`, `java.net` for ready-to-use functionalities. ✅ *User-defined Packages* – Create custom packages to organize projects. ✅ *Import Statements* – Access classes from other packages easily with `import package.ClassName` or `import package.*`. 💡 Key : Proper use of packages makes Java projects *modular, maintainable, and scalable*. #Java #Packages #ImportStatements #OOP #CodingSkills #LearningJourney #Programming
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development