Removing Elements from ArrayList Removing Elements from ArrayList – Do It Correctly Many developers write: for(String s : list) { list.remove(s); // ❌ Wrong } This throws: 👉 ConcurrentModificationException Because ArrayList iterator is fail-fast. Correct ways: ✔ Use Iterator: Iterator<String> it = list.iterator(); while(it.hasNext()) { it.remove(); } #Java #ArrayList #CollectionsFramework #BackendDevelopment #Programming #JavaDeveloper #CleanCode #SoftwareEngineering #TechGrowth #SpringBoot #day45ofJavaandSpringboot
Ajinkya Kothe’s Post
More Relevant Posts
-
Both ArrayList and LinkedList implement the List interface, but they behave very differently internally Use ArrayList when you need fast access and more read operations Use LinkedList when you have frequent insertions or deletions #Java #JavaCollections #ArrayList #LinkedList #DSA #Coding #Programming #SoftwareDevelopment #LearnJava #LinkedInPost
To view or add a comment, sign in
-
-
Spring Boot allows us to pass command line arguments while running the application, and these arguments can override values defined in application.properties or application.yml. #SpringBoot #Java #BackendDevelopment #SpringFramework #SoftwareDevelopment #Programming #Developers #LearningInPublic
To view or add a comment, sign in
-
⚡ A Simple Rule for Better APIs If your API endpoint needs a long explanation… It’s probably designed wrong. Good APIs should be understandable just by reading the endpoint. Example: Bad: /getUserDataById Better: /users/{id} Clear APIs reduce bugs, confusion, and documentation. Sometimes good design is just simplicity. 💬 What API design mistake do you see most often? #API #SoftwareEngineering #Developers #Programming #CodingTips
To view or add a comment, sign in
-
4 Common ArrayList Mistakes Developers Make ❌ 1. Removing While Iterating (Enhanced For Loop) Leads to → ConcurrentModificationException ❌ 2. Not Pre-Sizing Large Lists Frequent resizing = new array creation = performance overhead. ❌ 3. Using ArrayList in Multi-Threaded Apps It is NOT thread-safe. ❌ 4. Ignoring Time Complexity Insert/delete in middle = O(n) #Java #ArrayList #CollectionsFramework #BackendDevelopment #JavaDeveloper #Programming #SoftwareEngineering #Performance #Coding #TechCareer #SpringBoot #day46ofJavaandSpringboot
To view or add a comment, sign in
-
-
TypeScript 6.0 RC marks the final major release built on the current JavaScript-based compiler as the project prepares for a major architectural shift. The release is designed to align developers with the upcoming Go-based TypeScript 7.0 implementation focused on improved speed, memory efficiency, and scalability. See what this transition means for developers: https://lnkd.in/dYwRjQya #TypeScript #JavaScript #DevTools #SoftwareDevelopment #Programming
To view or add a comment, sign in
-
-
📌Exceptions vs Errors in Java ✅ Exception → A problem your program can handle. ❌ Error → A serious issue that usually crashes the application. Understanding this difference helps you write more stable and production-ready applications. 📌 Key takeaway: Handle Exceptions in your code, but Errors usually indicate system-level failures. What’s the best example of an Exception you have handled in your projects? 👇 #Java #BackendDevelopment #Programming #JavaDeveloper #Coding #SoftwareDevelopment #SpringBoot By ~ AZMAT ALLI KHAN
To view or add a comment, sign in
-
-
for loop example for(int i = 1; i <= 5; i++) { System.out.println(i); } while loop example int i = 1; while(i <= 5) { System.out.println(i); i++; } You can write this as your caption: 🔹 Understanding the Difference Between for Loop and while Loop Both for and while loops are used for repeating tasks in programming. ✔ for loop is best when the number of iterations is known. ✔ while loop is useful when the loop depends on a condition and the number of iterations is unknown. Choosing the right loop improves code readability and efficiency. #Java #Programming #Coding #Loops #Learning #CodeGnan
To view or add a comment, sign in
-
-
Day 3 of Coding Consistency 🚀 Today I solved the Abundant Number problem in Java. An Abundant Number is a number where 👉 Sum of its proper divisors > the number itself Example: 12 → divisors (1+2+3+4+6 = 16) 16 > 12 → Abundant Number Consistency > Motivation. 100 Days of Code continues. #java #leetcode #coding #programming #100daysofcode #developer #codingjourney
To view or add a comment, sign in
-
🔁 Recursion Made Simple When a function calls itself — that’s Direct Recursion. When it calls another function that calls it back — that’s Indirect Recursion. 💡 Example: Factorial of 6 6 × 5 × 4 × 3 × 2 × 1 = 720 Base Case ➝ Stops the recursion Recursive Call ➝ Breaks problem into smaller parts Think smaller. Solve smaller. Build bigger. 🚀 #Java #Recursion #Programming #CodingLife #DataStructures #LearnToCode
To view or add a comment, sign in
-
-
PROBLEM #10 ⚡ , MOVE ZEROES, in #leetcode by using two pointer method. swapping the non zeroes to the left and the zeroes to the right. time complexity - o(n); #problemsolving #dsa #arrays #geeksforgeeks #java #programming #computerscience #developer #datastructuresandalgorithms
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
to avoid that we can use CopyOnWriteArrayList<>()