🚀 One Java Performance Mistake You Might Be Making Looks simple… but can hurt performance 👇 for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } 👉 What’s the issue? - "list.size()" is called every iteration - In some implementations, it can be costly ✅ Better approach: for (int i = 0, size = list.size(); i < size; i++) { System.out.println(list.get(i)); } OR even better 👇 for (String item : list) { System.out.println(item); } ✔ Cleaner ✔ More readable ✔ Avoids unnecessary calls 🔥 Real impact: Small optimizations matter in large-scale systems. 💡 Lesson: Write efficient loops — they run more than you think. Do you prefer traditional loops or enhanced for-loops? 👇 #Java #Performance #CodingTips #CleanCode #Developers #Programming
Great share 👍
Very Helpful 👍
If you don't wanna use compact for loop, (or would not remember 4 step for loop) One more way is the old fashioned way. Store it in a variable: {variable} size = list.size(); for(int i=0;i<size;i++){}. same thing. or use streams as java8 is minimal in this economy 😋😄