🚀 Day 53 – Mastering ArrayDeque in Java Today I explored one of the most efficient data structures in Java Collections – ArrayDeque 🔥 📌 Key Learnings: 🔹 ArrayDeque is a resizable array-based Deque (Double Ended Queue) 🔹 Supports insertion & deletion from both ends (front & rear) 🔹 No indexing → cannot use get/set methods 🔹 No null values allowed (throws runtime exception) 🔹 Duplicates & heterogeneous data allowed 🔹 Faster than LinkedList due to no memory overhead ⚙️ Traversal Techniques: ✔ For-each loop ✔ Iterator ✔ Descending Iterator (reverse traversal) 💡 Why ArrayDeque? 👉 O(1) performance for add/remove operations 👉 Best choice for implementing: Stack (LIFO) Queue (FIFO) Deque 🧠 Big Takeaway: ArrayDeque = Fast + Memory Efficient + Flexible (Stack/Queue/Deque in one) Consistency is the key 🔑 — learning something new every day! #Java #DataStructures #ArrayDeque #JavaCollections #CodingJourney #100DaysOfCode #LearningDaily
Mastering ArrayDeque in Java: Efficient Data Structure
More Relevant Posts
-
Day 7 of #100DaysOfCode — Java is getting interesting ☕ Today I explored the Java Collections Framework. Before this, I was using arrays for everything. But arrays have one limitation — fixed size. 👉 What if we need to add more data later? That’s where Collections come in. 🔹 Key Learnings: ArrayList grows dynamically — no size worries Easy operations: add(), remove(), get(), size() More flexible than arrays 🔹 Iterator (Game changer) A clean way to loop through collections: hasNext() → checks next element next() → returns next element remove() → safely removes element 🔹 Concept that clicked today: Iterable → Collection → List → ArrayList This small hierarchy made everything much clearer. ⚡ Array vs ArrayList Array → fixed size ArrayList → dynamic size Array → stores primitives ArrayList → stores objects Still exploring: Set, Map, Queue next 🔥 Consistency is the only plan. Showing up every day 💪 If you’re also learning Java or working with Collections — let’s connect 🤝 #Java #Collections #ArrayList #100DaysOfCode #JavaDeveloper #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 54 – Mastering TreeSet in Java Today I explored one of the most powerful classes in the Java Collection Framework — TreeSet. 🔍 Key Learnings: ✅ Stores unique elements (no duplicates) ✅ Maintains automatic sorting (ascending order) ✅ Uses Binary Search Tree (BST) internally ✅ Sorting is achieved using Inorder Traversal (LVR) ✅ Does not allow null values ✅ Does not support heterogeneous data (requires comparison) 📌 Important Concepts: Left < Root < Right (BST logic) No indexing → cannot use traditional for loop Access using Iterator / For-Each Supports both ascending & descending traversal 🛠️ Methods I Practiced: first() & last() headSet(), tailSet(), subSet() ceiling(), floor(), higher(), lower() pollFirst(), pollLast() 💡 Real-world Use Case: Useful for building features like leaderboards, ranking systems, and sorted data processing. 📈 Understanding how TreeSet works internally (BST + traversal) really helped me connect Data Structures with Java Collections. #Java #CollectionsFramework #TreeSet #DataStructures #LearningJourney #100DaysOfCode #JavaDeveloper
To view or add a comment, sign in
-
-
Solved Sort Characters By Frequency -> LeetCode Medium, String + HashMap in Java. What I built: Count frequency of each character using HashMap, convert it to a list, sort by frequency in decreasing order, then build the result using StringBuilder. Problem I faced: First I tried storing frequencies in an array and sorting it , but that was O(n log n). Switched to HashMap for frequency counting which brings sorting down to O(k log k) where k is number of unique keys. Since max ASCII characters are 128, it's basically O(1). The part I got stuck on -> I didn't know how to sort a HashMap. Googled it, found out HashMap can't be sorted directly. So converted it to a List of entries and sorted that using a lambda comparator. Took help for two things only — how to sort a HashMap, and the syntax for the comparator. Logic was mine. Still learning HashMap operations properly, but slowly getting comfortable . Open to better approaches! Github: https://lnkd.in/gBgb3jAK #DSA #Java #LeetCode #HashMap #Strings #LearningInPublic
To view or add a comment, sign in
-
Day 51-What I Learned In a Day (JAVA) Today I stepped into the next important concept in Java -Non-Static Members. Unlike static members, non-static members belong to an object, not the class. This means they require an instance of the class to be accessed. What are Non-Static Members? Non-static members include: • Non-static variables (instance variables) • Non-static methods • Constructors Key Understanding: 🔹 Instance Variables Each object has its own copy of variables. Changes in one object do not affect another. 🔹 Non-Static Methods These methods can directly access both static and non-static members. They require object creation to be called. 🔹 Object Creation is Mandatory !To access non-static members: ClassName obj = new ClassName(); Important Difference I Learned: • Static → Belongs to class (no object needed) • Non-Static → Belongs to object (object required) What I Realized Today: Understanding non-static members is crucial because real-world applications mainly work with objects. This concept is the base for Object-Oriented Programming (OOP). #Java #OOP #Programming #LearningJourney #DeveloperLife
To view or add a comment, sign in
-
Day 33/100 — Threads & Multithreading ⚡ Java can do multiple things at the same time using threads. Thread lifecycle: NEW → RUNNABLE → RUNNING → WAITING → TERMINATED 2 ways to create threads: // Method 1: extend Thread class MyThread extends Thread { public void run() { println("Running!"); } } new MyThread().start(); // NOT run()! // Method 2: Runnable lambda (preferred!) Thread t = new Thread(() -> println("Lambda thread!")); t.start(); Most important rule: ALWAYS call start() — NOT run()! → run() = normal method call (same thread) → start() = creates new thread and calls run() 3 things to remember: → Prefer Runnable over extending Thread → start() not run() → Multiple threads = race conditions possible! 🎯 Challenge: Create 3 threads that each print their name 5 times. Observe the interleaved output! #Java #Threads #Multithreading #CoreJava #100DaysOfJava #100DaysOfCode
To view or add a comment, sign in
-
-
Day 52-What I Learned In a Day (JAVA) Today I learned some fundamental concepts in Java related to objects and methods. 🔹 Creating Objects (for Non-Static Methods) Understood that to access non-static methods, we must create an object of the class. 🔹 Steps to Create an Object 1️⃣ Declare reference variable 2️⃣ Create object using new keyword 3️⃣ Assign it to the reference 🔹 new Keyword Learned that it is used to allocate memory in the heap and create an object. 🔹 Non-Primitive Data Types Explored how objects, arrays, and classes store references instead of actual values. 🔹 Accessing Data from Another Class Learned how to access variables and methods from another class by creating an object of that class and using the reference. These concepts helped me understand how Java objects work, how memory is managed, and how classes interact with each other. #Java #OOP #Programming #LearningJourney #Coding #100DaysOfCode
To view or add a comment, sign in
-
-
🦾 The Power of ForkJoin in Java When dealing with massive datasets or computationally heavy tasks, sequential processing is often the bottleneck. That’s where the ForkJoin Framework shines, implementing a "Divide and Conquer" strategy at the hardware level. Here is how it overcomes common parallelism challenges: 1. Efficient Resource Allocation (Work-Stealing) This is the "secret sauce." In a typical thread pool, if one thread finishes its tasks, it sits idle while others might be overwhelmed. In a ForkJoinPool, idle threads "steal" work from the back of the deques of busy threads. This ensures all CPU cores are consistently utilized. 2. Solving the "Divide and Conquer" Complexity Managing recursion and thread synchronization manually is error-prone. ForkJoin provides a structured way to: Fork: Split a large task into smaller, independent sub-tasks. Join: Wait for the sub-tasks to finish and combine their results. 3. Lightweight Task Management Unlike standard OS threads, ForkJoin tasks (like RecursiveTask or RecursiveAction) are extremely lightweight. You can run millions of these tasks within a much smaller pool of actual worker threads without the overhead of context switching. When should you use it? Recursive Problems: Like sorting large arrays (Parallel Sort) or processing complex tree structures. CPU-Intensive Work: When you have a lot of data and enough cores to handle it in parallel. Large Collections: When a simple for loop is no longer meeting your SLA. Pro-tip: For most everyday tasks, Java's parallelStream() uses a common ForkJoinPool under the hood. However, for specialized heavy-lifting, creating your own ForkJoinPool gives you much finer control over parallelism levels. #Java #Multithreading #ParallelComputing #Backend #SoftwareEngineering #Performance #Concurrency
To view or add a comment, sign in
-
-
🚀 Day 51 – Mastering LinkedList in Java Today I explored one of the most important data structures in Java Collections – LinkedList. 🔍 Key Learnings: ✔ Understood how LinkedList works internally using Doubly Linked List (nodes) ✔ Learned the difference between ArrayList vs LinkedList (dynamic vs node-based storage) ✔ Explored constructors and how to copy data using Collection constructor ✔ Deep dive into Polymorphism & Loose Coupling in real-time usage 💡 Accessing Elements Techniques: 🔹 For Loop (get(index)) 🔹 Enhanced For Loop (for-each) 🔹 Iterator (forward traversal) 🔹 ListIterator (forward + backward traversal) ⚡ Realization: Understanding how data is accessed and traversed is just as important as storing it. Concepts like Iterator vs ListIterator are very crucial for interviews. 📈 Step by step, building strong foundations in Core Java & Collections Framework #Java #LinkedList #CollectionsFramework #CoreJava #Programming #LearningJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🧱 SOLID Principles in Java – Write Code That Doesn't Come Back to Haunt You You know that feeling when touching one feature breaks three unrelated things? That's what life looks like without SOLID principles. I just published a deep-dive post covering all five principles with real Java examples: ✅ Single Responsibility – One class, one job. Stop your Invoice class from moonlighting as a printer AND a database. ✅ Open/Closed – Extend behavior without cracking open existing code. No more endless if-else chains. ✅ Liskov Substitution – Your Penguin shouldn't throw UnsupportedOperationException when asked to fly. ✅ Interface Segregation – Stop forcing Robots to implement an eat() method. ✅ Dependency Inversion – Depend on abstractions, not implementations. Your service shouldn't care if it's MySQL or PostgreSQL. 🔗 Read the full post: https://lnkd.in/gfA5g8VG #Java #SOLID #CleanCode #SoftwareEngineering #OOP #DesignPrinciples #BackendDevelopment #SpringBoot #Programming #TechBlog #100DaysOfCode
To view or add a comment, sign in
-
Java Collections seem straightforward… until edge cases start showing up in real-world code. Here are a few more collection behaviors worth knowing 👇 • Null handling in collections HashMap allows one null key, Hashtable allows none — small difference, big impact. • contains() vs containsKey() Using the wrong one in Map can lead to incorrect checks. • Size vs Capacity (ArrayList) size() is actual elements, capacity is internal storage — confusion can lead to performance issues. • remove() ambiguity in List remove(1) removes by index, not value — use remove(Integer.valueOf(1)) for value. • equals() & hashCode() importance Custom objects in HashSet/HashMap need proper overrides or duplicates may appear. • Iteration order assumptions HashMap order is unpredictable — don’t rely on it unless using LinkedHashMap or TreeMap. • Immutable collections (List.of) They throw UnsupportedOperationException on modification — common runtime surprise. Small collection details like these often lead to big debugging sessions. #Java #BackendDevelopment #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