Java Set Removes Duplicates

Can you spot what happens here? 👇 Set<Integer> set = new HashSet<>(); set.add(1); set.add(1); set.add(2); System.out.println(set.size()); 👉 Output: 2 ✅ Reason? Set does not allow duplicate values. So even though we added 1 twice, it gets stored only once. 💡 Simple concept, but easy to overlook. Have you used Set in your projects? 👇 #Java #CoreJava #Programming #BackendDeveloper #Coding #TechLearning

To view or add a comment, sign in

Explore content categories