Java Collections, DSA, and JUnit Revision

Day 15 — #100DaysJava three things in one day. Collections, DSA, and JUnit revision. ☕ Some days you just lock in. ----------------------------- Thing 1 — Collections detail I never knew I always used ArrayList without thinking. Today I learned there are actually three different ways to create a list in Java and they behave completely differently. Arrays.asList() — fixed size. You can update values but you cannot add or remove. Most people think it works like ArrayList. It does not. List.of() — completely immutable. Nothing can change. Not even the values. And it does not allow null. This is the safest option when you want data that should never change. ArrayList — fully dynamic. Add, remove, update — everything works. This is what you use when the data needs to change. One line to remember: Arrays.asList = fixed, List.of = immutable, ArrayList = flexible. Small difference. Huge impact in interviews and real code. --- Thing 2 — Queue in Java (DSA) Queue follows FIFO — First In, First Out. Like a line at a ticket counter. First person in line gets served first. Three ways to use Queue in Java: LinkedList — simple, most common PriorityQueue — automatically sorts elements, smallest comes out first ArrayDeque — fastest, preferred in interviews The method pairs every Java developer should know: offer() vs add() — offer is safe, add throws exception if it fails poll() vs remove() — poll returns null if empty, remove throws exception peek() vs element() — peek returns null if empty, element throws exception Always use the safe version — offer, poll, peek. Problems I practiced: Reverse a queue using a stack Generate binary numbers using a queue Implement queue using two stacks --- Thing 3 — JUnit 5 revision Went back through everything from Day 13 and 14. Rewrote test cases for Calculator and String utilities from scratch without looking at notes. The AAA pattern is now muscle memory — Arrange, Act, Assert. Also revised edge cases — null inputs, empty strings, boundary values. This is where real bugs hide. --- 15 days in. The concepts are connecting now. DSA problems feel less scary when you understand the data structures behind them. If you are learning Java — save this post. Arrays.asList vs List.of vs ArrayList comes up in almost every Java interview. 📌 Day 1 ........................................Day 15 ✅ What DSA topic do you find hardest to crack in interviews? Drop it below — let us discuss! 🙏 #Java #DSA #DataStructures #Queue #Collections #JUnit #100DaysOfJava #JavaDeveloper #LearningInPublic #BackendDevelopment #100DaysOfCode #InterviewPrep #CodingInterview

To view or add a comment, sign in

Explore content categories