🚀 You use ArrayList every day. But do you know what’s hiding under the hood? 👇 We all use this line every day 👇 List<String> list = new ArrayList<>(); Here’s the real inheritance chain 👇 Iterable ↓ Collection (extends Iterable) ↓ AbstractCollection (implements Collection) ↓ List (extends Collection) ↓ AbstractList (extends AbstractCollection, implements List) ↓ ArrayList (extends AbstractList, implements List, RandomAccess, Cloneable, Serializable) 💡 Quick takeaways: ✅ Iterable is what makes enhanced for-loops (for-each) possible. ✅ AbstractCollection & AbstractList provide skeleton implementations so subclasses only need to implement key methods. ✅ ArrayList adds dynamic resizing, fast lookups, and cloning support. ⚙️ Hidden Insight: Your everyday ArrayList isn’t just a list — it’s a layered masterpiece of interfaces + abstract classes + marker interfaces that make it fast, flexible & reliable 🚀 #Java #Coding #DeveloperTips #ArrayList #Programming #LearnJava #OOP
What's under the hood of ArrayList?
More Relevant Posts
-
Hey Uplifters! 👋 Problem of the Day (05-11-2025) 3321 - Find X-Sum of All K-Long Subarrays II This was a really challenging problem in terms of implementation! Problem in short: • You’re given an array of integers nums and two integers k and x. • Your task is to calculate the "x-sum" for every subarray (sliding window) of size k. • The x-sum is the sum of the top x most frequent elements in the window. If frequencies are tied, the element with the larger value wins. 💡 Intuition • We need to find the sum of the top x most frequent elements in every subarray of size k. • Instead of starting over for each window, we can slide the window and just update what changes — the new element added and the old one removed. • To efficiently keep track of the most frequent elements, we maintain two ordered groups: • One for the top x elements • One for the remaining elements ⚙️ Approach • Use a HashMap to count how often each number appears. • Use two TreeSets (or ordered structures): • large → top x frequent (and higher values on ties) • small → the rest • Keep a running sum tot of all elements in large. • As we slide the window: • Update frequencies when elements enter or leave • Move elements between large and small if needed • Keep large always containing the correct top x •Add tot to the answer for each window. LeetCode Solution: https://lnkd.in/gEgcHHXJ (Since this is a lengthy implementation problem, I couldn’t cover the full logic in this post. You can check out my detailed solution on LeetCode. If you have any questions, feel free to DM me or drop your doubts in the comments!) Let’s keep learning and growing together! 🌱 #LeetCode #POTD #ProblemOfTheDay #DailyChallenge #CodingChallenge #DataStructures #Algorithms #ProblemSolving #Java #JavaProgramming #LearnToCode #TechCommunity #SoftwareDevelopment #Programming #Uplifters
To view or add a comment, sign in
-
This one LeetCode problem taught me more about discipline than syntax..!! Today’s focus: LeetCode 221 — Maximal Square A neat little problem that blends dynamic programming and pattern recognition beautifully. Each time I solve one of these, it’s less about getting the “Accepted” and more about strengthening how I think through problems. A step by step, logically and creatively. As developers, we spend a lot of time debugging, optimizing, and refactoring, but it’s these small daily problem-solving habits that keep our logical muscles in shape. #Java #LeetCode #CodingJourney #ProblemSolving #SoftwareEngineering #LearningMindset
To view or add a comment, sign in
-
-
🚀 Why @Autowired Is No Longer the Cool Kid in Spring Boot Once upon a time, @Autowired was the star of dependency injection in Spring Boot. But as best practices evolved, developers started to realize… it’s not always the best choice anymore. Let’s unpack why 👇: 💣 The Problem with @Autowired : 1. Hidden Dependencies Field injection hides what your class actually depends on — making debugging and testing feel like detective work. 🕵️♂️ 2. No Immutability : Dependencies injected via fields can change after initialization… a recipe for subtle, hard-to-find bugs. 3. Harder Testing : Mocking dependencies in tests gets messy. More setup, more pain. 4. Less Clarity : With field injection, you can’t instantly tell what a class needs to work. That’s bad for readability and maintainability. 💡 The Case for Constructor Injection: So what’s better? Constructor Injection ✅ 1. Makes Dependencies Explicit : The constructor shows exactly what your class requires. No surprises. 2. Immutable by Design : Using final fields means dependencies can’t be reassigned later. 3. Testing Made Simple : Just pass your mocks directly through the constructor — no Spring context needed. 4. Cleaner Code : If your class has a single constructor, Spring will inject dependencies automatically — no @Autowired required. ⚙️ Bonus Tip: Lombok to the Rescue Thanks to Lombok, you can keep things clean and concise: @Service @RequiredArgsConstructor public class MyService { private final MyRepository myRepository; } No boilerplate. No clutter. Just elegance. ✨ 💬 When @Autowired Still Makes Sense * Setter Injection — for optional dependencies. * Legacy Code — don’t refactor everything at once; just adopt constructor injection in new or updated classes. 👉🏻👉🏻 ✅ Constructor Injection = clarity + immutability + easy testing ✅ Lombok = less code, same power ⚠️ @Autowired = use only when necessary #SpringBoot #Java #CleanCode #Lombok #SoftwareEngineering #BackendDevelopment #CodingBestPractices #SpringFramework #DeveloperTips #CodeQuality #Programming #DependencyInjection #TechLeadership
To view or add a comment, sign in
-
📌 Day 155 of Coding - Next Greater Numerically Balanced Number (LeetCode - Medium) 🎯 Goal: Find the smallest integer greater than n such that the count of each digit d in the number is exactly d (for digits 1-7). 💡Approach & Debugging: Used backtracking to generate all “beautiful” numbers following the digit count rule. A helper function generate() recursively built numbers by trying digits 1-7, ensuring that no digit appeared more times than its own value. Checked each generated number using isBeautiful(). After generation, sorted the list and returned the first number greater than n. ✔️ Time Complexity: Exponential (backtracking-based generation, but limited by small constraints). ✔️ Space Complexity: O(1) auxiliary + O(M) list for generated numbers. 🧠 Key Takeaways: Precomputation and pruning (like limiting to 1224444) help keep recursion efficient. Problems mixing digit frequency logic and recursion sharpen number theory intuition. #Day155 #LeetCode #Backtracking #Recursion #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🌟 Day 41 of #100DaysOfCode 🌟 🔍 Exploring String Reversal — Simplicity in Motion 🔹 What I Solved Today’s challenge focused on one of the most fundamental yet essential problems — reversing a string in-place. No shortcuts, no helper strings — just clean pointer manipulation and precision. 🧩 Problem: Reverse a String (In-Place) 💡 Problem Statement Given an array of characters s, reverse it in-place. You must modify the input array directly, without using any extra memory. 💡 Example 1: Input: ["h","e","l","l","o"] → Output: ["o","l","l","e","h"] 💡 Example 2: Input: ["H","a","n","n","a","h"] → Output: ["h","a","n","n","a","H"] 🧠 Concepts Used Two-Pointer Technique 🔁 In-Place Array Manipulation Constant Space Optimization ⚙️ Approach 1️⃣ Use two pointers — one at the start (left) and one at the end (right). 2️⃣ Swap characters at both ends. 3️⃣ Move both pointers toward the center until they meet. 🚀 What I Learned ✨ Two-pointer techniques make complex tasks effortless. ✨ In-place operations strengthen logic and memory efficiency. ✨ Simplicity is often the most elegant form of problem-solving. 💬 Reflection Today’s challenge was a reminder that mastery begins with fundamentals. Sometimes, the most impactful solutions are built on clear, minimal logic — where simplicity meets efficiency. #100DaysOfCode #Day41 #ReverseString #TwoPointer #DSA #Java #LeetCode #Algorithm #ProblemSolving #CleanCode #ProgrammingJourney #MindfulCoding #CodeOptimization #StringManipulation
To view or add a comment, sign in
-
-
🚀 Day 40 of My #LeetCode Challenge 🚀 📘 Problem: Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold (LeetCode #1343) 💡 Approach: Implemented the Sliding Window technique to efficiently calculate the sum of each subarray of size k. First, compute the sum of the initial k elements. Then, slide the window forward — subtract the element leaving and add the new one entering. Check if the average of the current window meets or exceeds the given threshold. This method optimizes the time complexity to O(n) by avoiding repetitive summation. ⏱️ Concepts Used: Sliding Window | Arrays | Optimization | Time Complexity 🔥 Consistency and logic go hand in hand — every day adds a new layer to my problem-solving skills! #Day40 #LeetCode #100DaysOfCode #CodingChallenge #Java #DSA #ProblemSolving #CodingJourney #TechLearning #CodeEveryday #SoftwareEngineering #ProgrammerLife #CodingCommunity #Developer #JavaProgramming #LearnToCode #TechGoals #CodeNewbie #Algorithm #DataStructures #CodingPractice
To view or add a comment, sign in
-
-
#Day-44) of Problem Solving | LeetCode 2011 – Final Value of Variable After Performing Operations Just solved a fun one! 🚀 This problem tests how well you can interpret simple string-based operations and apply them efficiently. Given a list of operations like "++x", "x--", etc., the goal is to compute the final value of a variable starting from zero. 🔍 My approach (Java): Used String.indexOf("+") to detect increment operations and updated the counter accordingly. Clean, readable, and runs in linear time. #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #PranshuCodes #LinkedInCoding #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 63 of My LeetCode journey 🚀 Problem : Custom Sort String Today’s problem was interesting because instead of sorting using normal alphabetical order, we sort the given string based on a custom priority order. 🧠 Problem Understanding Given: order → defines priority of characters. str → the input string which needs to be rearranged. Goal: ✅ Arrange characters of str based on the sequence defined in order. ✅ Characters not present in order should appear at the end (any order). 💡 Approach (Simple & Efficient) Count frequency of each character in str. First append characters following the order. Then append remaining characters. Time Complexity: O(n) Space Complexity: O(1) (fixed array size for 26 letters) ✨ Learnings Sometimes the problem isn't about sorting, but about following a custom priority. Frequency counting is extremely powerful for character-based problems. StringBuilder → best way to build strings efficiently in Java. #leetcode #coding #dsa #java #100DaysOfCode #day63 #learningEveryday #problemSolving
To view or add a comment, sign in
-
More from this author
Explore related topics
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