Day 58 of Sharing What I’ve Learned 🚀 Map in Java — Storing Data as Key-Value Pairs After learning how PriorityQueue processes elements based on priority, I explored another powerful concept — Map. 👉 It doesn’t store just values… it connects keys with values 🔹 What is a Map? Map is a part of the Java Collections Framework that stores data in key-value pairs. 👉 Each key is unique and maps to a value 🔹 How does Map work? 👉 Data is stored as (key → value) 👉 Keys must be unique 👉 Values can be duplicated ✔ put() → adds key-value pair ✔ get() → retrieves value using key ✔ remove() → deletes entry ✔ containsKey() → checks key existence 🔹 Types of Map ✔ HashMap → Fast, unordered ✔ LinkedHashMap → Maintains insertion order ✔ TreeMap → Sorted by keys 🔹 Why use Map? ✔ Fast lookup using keys ✔ Efficient data organization ✔ Useful for real-world mappings 🔹 Real-World Use Cases 👉 Storing student data (ID → Name) 👉 Caching systems 👉 Frequency counting 👉 Database indexing 🔹 Key Features ✔ No duplicate keys ✔ Allows one null key (HashMap) ✔ Not synchronized (HashMap) ✔ Faster retrieval compared to lists 🔹 When should we use Map? 👉 Use it when: ✔ You need fast lookup by key ✔ You want structured data (pair format) ✔ You need efficient searching 🔹 When NOT to use? ❌ When you only need a list of values ❌ When order matters strictly (use LinkedHashMap/TreeMap carefully) 🔹 Key Insight 💡 Map is not about storing data… 👉 It’s about connecting data 🔹 Day 58 Realization 🎯 Efficient programs don’t just store values… 👉 They organize relationships between them #Java #Map #HashMap #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day58 Grateful for guidance from, Sharath R TAP Academy kshitij kenganavar
Mohammed Usman shaik’s Post
More Relevant Posts
-
🚀 TreeSet in Java Collections Continuing my journey in Set-based collections, I explored TreeSet, which introduces sorting + uniqueness in data storage. 🔹 What is TreeSet? TreeSet is a class in Java Collections Framework that stores unique elements in sorted order By default, it follows natural ordering (ascending order) 🔹 Key Properties ✅ Maintains sorted order (ascending by default) ❌ Does not allow duplicates ❌ Does not allow null values ⚠️ Heterogeneous data allowed only if Comparator is provided Implements SortedSet & NavigableSet 🔹 Internal Working Uses Balanced Binary Search Tree (Red-Black Tree) Automatically keeps elements sorted 👉 Sorting is based on: Comparable (natural sorting) Comparator (custom sorting) 🔹 Constructors TreeSet() TreeSet(Comparator c) TreeSet(Collection c) TreeSet(SortedSet s) 🔹 Important Methods add(E e) remove(Object o) contains(Object o) first() → smallest element last() → largest element headSet(E e) → elements < e tailSet(E e) → elements ≥ e subSet(from, to) → range ceiling(E e) → smallest ≥ e size() 🔹 Traversal (Accessing Elements) For-each loop Iterator Stream API ❌ No indexing ❌ No ListIterator 🔹 Performance Add / Remove / Search → O(log n) Slower than HashSet (because of sorting) 🔹 TreeSet vs HashSet vs LinkedHashSet HashSet → No order LinkedHashSet → Insertion order TreeSet → Sorted order 👉 TreeSet is best when: Sorted data is required Range-based operations are needed 🔹 When to Use TreeSet? When sorted output is required When working with range queries When needing ordered traversal automatically 🔹 Learning Outcome Strong understanding of sorted collections Clear difference between HashSet vs LinkedHashSet vs TreeSet Knowledge of Comparable vs Comparator Ability to choose correct Set implementation 🙌 Special thanks to the amazing trainers at TAP Academy: kshitij kenganavar Sharath R MD SADIQUE Bibek Singh Vamsi yadav Hemanth Reddy Harshit T Ravi Magadum Somanna M G Rohit Ravinder TAP Academy Grateful to Tap Academy for strengthening my Java and data structure foundations 🚀 #TapAcademy #Week13Learning #CoreJava #CollectionsFramework #TreeSet #HashSet #LinkedHashSet #DataStructures #JavaFundamentals #LearningByDoing #FullStackJourney #VamsiLearns
To view or add a comment, sign in
-
-
Day 59 of Sharing What I’ve Learned 🚀 Comparator in Java — Custom Sorting Made Easy After learning how Map stores key-value pairs, I explored something powerful — controlling how data is sorted using Comparator. 👉 Default sorting is useful… but real-world problems need custom logic 🔹 What is Comparator? Comparator is an interface in Java used to define custom sorting logic. 👉 It allows us to sort objects based on our own rules 🔹 How does Comparator work? 👉 We override compare(a, b) method 👉 Returns: ✔ Negative → a comes before b ✔ Zero → both are equal ✔ Positive → a comes after b 🔹 Why use Comparator? ✔ Custom sorting logic ✔ Multiple sorting options ✔ Works without modifying the original class 🔹 Real-World Use Cases 👉 Sorting students by marks 👉 Sorting employees by salary 👉 Sorting products by price or rating 🔹 Key Features ✔ External sorting logic (separate from class) ✔ Can create multiple comparators ✔ Works with Collections.sort() & Arrays.sort() 🔹 Comparator vs Comparable 👉 Comparable = default/internal sorting 👉 Comparator = custom/external sorting 🔹 When should we use Comparator? 👉 Use it when: ✔ You need multiple ways to sort data ✔ You don’t want to modify the class ✔ You need dynamic sorting logic 🔹 When NOT to use? ❌ When only one natural sorting is enough ❌ When simple primitive sorting is required 🔹 Key Insight 💡 Sorting is not just arranging data… 👉 It’s about organizing data based on needs 🔹 Day 59 Realization 🎯 Good developers don’t just sort data… 👉 They decide how it should be sorted #Java #Comparator #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day59 Grateful for guidance from, TAP Academy Sharath R kshitij kenganavar
To view or add a comment, sign in
-
-
Day 52 of Sharing What I’ve Learned 🚀 LinkedList in Java — Advantages & Disadvantages After exploring how LinkedList powers structures like Queue, I took a step back to understand something important — 👉 When should we actually use LinkedList, and when should we avoid it? 🔹 Advantages of LinkedList ✔ Dynamic Size No need to define size in advance — it grows and shrinks as needed. ✔ Efficient Insertions & Deletions Adding/removing elements is fast, especially at the beginning or middle. (No shifting like arrays!) ✔ Memory Utilization (Flexible Allocation) Memory is allocated as needed, not wasted upfront. ✔ Implements Multiple Structures Can be used as: ✔ List ✔ Queue ✔ Deque 🔹 Disadvantages of LinkedList ❌ More Memory Usage Each node stores extra references (pointers), increasing memory overhead. ❌ Slow Access (No Indexing) Unlike ArrayList, you can’t directly access elements — traversal is required. ❌ Poor Cache Performance Elements are not stored contiguously → slower compared to arrays. ❌ Not Ideal for Searching Searching is O(n), making it inefficient for large datasets. 🔹 LinkedList vs ArrayList (Quick Insight) 👉 Use LinkedList when: ✔ Frequent insertions/deletions ✔ Working with Queue/Deque 👉 Use ArrayList when: ✔ Fast access is needed ✔ More read operations than write 🔹 Key Insight 💡 Every data structure has trade-offs — 👉 The real skill is knowing when to use which one. 🔹 Day 52 Realization 🎯 Understanding limitations is just as important as learning features — That’s what makes you a better problem solver. #Java #LinkedList #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day52 Grateful for guidance from, Sharath R TAP Academy
To view or add a comment, sign in
-
-
🚀 Day 56 & 57 – Mastering Maps in Java | Tap Academy Diving deeper into the Java Collections Framework, I explored one of the most powerful concepts — Maps, especially HashMap, LinkedHashMap, and TreeMap. 🔹 Day 56 Highlights – HashMap Understood how Map stores data in key–value pairs Learned internal working: Hashing (Hash Table + Hash Function) Explored default capacity (16) and load factor (75%) Practiced key features: ✔ No duplicate keys ✔ Allows null values ✔ Heterogeneous data support ✔ Fast operations → O(1) 💻 Implemented important methods: put(), get(), containsKey(), containsValue(), entrySet(), keySet(), values() 🔁 Learned how to iterate using: entrySet() (Map → Set conversion) Iterator (cursor-based access) 🔹 Day 57 Highlights – LinkedHashMap & TreeMap 📌 LinkedHashMap Maintains insertion order Same features as HashMap but ordered output 📌 TreeMap Stores data in sorted order (ascending by keys) Uses Tree structure (Red-Black Tree) No null keys allowed Slightly slower → O(log n) 📊 Comparison Insight HashMap → Fastest, no order ⚡ LinkedHashMap → Maintains insertion order 📌 TreeMap → Sorted order 🔄 🎯 Key takeaway: Choosing the right data structure matters based on requirement — speed, order, or sorting. 🎯 This journey is strengthening my problem-solving skills and deepening my understanding of how real-world data is handled efficiently. #Java #CollectionsFramework #HashMap #LinkedHashMap #TreeMap #DataStructures #FullStackJava #TapAcademy #LearningJourney 🚀
To view or add a comment, sign in
-
-
🚀 Exploring the Collection Framework in Java Ever wondered how Java efficiently manages large amounts of data? 🤔 Recently, I stepped into the Collection Framework—a powerful concept used for handling data effectively. 🔍 What is the Collection Framework? It is a collection of classes and interfaces that help in storing, manipulating, retrieving, and processing data easily. 💡 Why use it? ✔ Easy to store data ✔ Easy to manipulate ✔ Easy to retrieve ✔ Easy to process 📌 Core Interfaces: • List • Set • Map 🔗 Started with List Interface: Explored implementations like: • ArrayList • LinkedList • ArrayDeque • PriorityQueue 📊 What I analyzed: • Usage • Initial capacity • Heterogeneous data support ➡️ Then explored: • Insertion order • Duplicates • Null handling ➡️ Also looked into: • Constructors • Internal structure • Hierarchy 🔄 Ways to Access Elements: • For loop • For-each loop ➡️ Advanced ways: • Iterator • ListIterator 👉 Key Difference: Iterator moves only forward, whereas ListIterator supports both forward and backward traversal. 🌍 Real-Life Use Case: Imagine building a student management system 📚 • Use ArrayList to store and display student records • Use LinkedList for frequent insertions/deletions • Use PriorityQueue for priority-based processing 💡 Key Takeaway: Choosing the right data structure depends on the use case and performance requirements. 💻 Mini Code Example: import java.util.*; public class Demo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("Python"); for(String lang : list) { System.out.println(lang); } } } ✨ Special thanks to Sharath R for the clear and practical explanation! TAP Academy Bibek Singh #Java #Collections #CollectionFramework #ArrayList #LinkedList #DataStructures #OOP #Programming #FullStackDevelopment #LearningJourney #Coding #Developer #TapAcademy
To view or add a comment, sign in
-
-
Day 61 of Sharing What I’ve Learned🚀 Collections Utility Class in Java — Powerful Helpers for Data Manipulation After learning how sorting works using Comparable and Comparator, I explored something that makes working with collections even easier — the Collections utility class. 👉 Instead of writing logic from scratch… Java already gives us ready-made tools 🔹 What is Collections class? Collections is a utility class in Java that provides static methods to operate on collection objects. 👉 It works with List, Set, and more 👉 No need to create objects — just use methods directly 🔹 Commonly Used Methods ✔ sort() → Sorts elements ✔ reverse() → Reverses order ✔ shuffle() → Randomly shuffles elements ✔ min() / max() → Finds smallest & largest ✔ frequency() → Counts occurrences ✔ binarySearch() → Searches efficiently (on sorted list) 🔹 Why use Collections? ✔ Saves time (no need to write logic manually) ✔ Improves readability ✔ Optimized and efficient ✔ Reduces bugs 🔹 Real-World Use Cases 👉 Sorting student records 👉 Finding highest salary 👉 Randomizing quiz questions 👉 Searching data quickly 👉 Counting duplicates 🔹 Key Features ✔ Works with existing collections ✔ Provides static utility methods ✔ Supports Comparable & Comparator ✔ Part of Java Collections Framework 🔹 Collections vs Collection 👉 Collection = Interface (data structure) 👉 Collections = Utility class (helper methods) 🔹 When should we use it? 👉 Use when: ✔ You want ready-made operations ✔ You need optimized algorithms ✔ You want cleaner code 🔹 Day 61 Insight 💡 Don’t reinvent the wheel… 👉 Java already gives powerful tools — learn to use them effectively 🔹 Day 61 Realization 🎯 Writing less code doesn’t mean doing less work… 👉 It means using smarter tools #Java #Collections #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day61 Grateful for guidance from, TAP Academy Sharath R kshitij kenganavar
To view or add a comment, sign in
-
-
Day 37 of learning Java! Today I learned about Lambda Expressions, Functional Interfaces & Comparator 🔹 Why Lambdas? ✔ Java shifted towards functional programming ✔ Now we can pass behavior (functions) directly ✔ Earlier problem: • Needed full classes just for small logic • Too much boilerplate 🔹 Functional Interface ✔ Interface with only ONE abstract method ✔ Why important? → Enables lambda expressions ✔ Short way to write functions Forms: • (a, b) → a + b • x → x * x • () → some action • Multi-line → use {} 🔹 Key Concept: Target Typing ✔ Java automatically understands: • parameter types • return type → Based on context 🔹 Comparator Interface ✔ Used for custom sorting ✔ Unlike Comparable: • Comparable → fixed logic • Comparator → flexible logic ✔ Example use: • Sort by name • Sort by marks • Sort by roll number 🔹 Lambdas with Comparator ✔ Cleaner sorting logic ✔ No need for anonymous classes → Makes code shorter & readable 🔹 Old vs New Approach Old: • Anonymous classes • Verbose New (Lambda): • Concise • Readable • Functional style special thanks to Aditya Tandon Rohit Negi sir
To view or add a comment, sign in
-
-
Day 56 of Sharing What I’ve Learned🚀 TreeSet in Java — Sorted & Unique Elements After exploring how LinkedHashSet maintains insertion order, I moved to something even more powerful — TreeSet. 👉 It not only stores unique elements but also keeps them automatically sorted 🔹 What is TreeSet? TreeSet is an implementation of the Set interface that stores unique elements in sorted order. 👉 It is internally based on a Red-Black Tree (self-balancing binary search tree) 🔹 How does TreeSet store & sort data? 👉 Elements are stored in a tree structure, not randomly 👉 While inserting, elements are placed in a way that keeps the tree balanced 👉 Data is always arranged in ascending order (default) ✔ Smallest element → left side ✔ Largest element → right side ✔ In-order traversal → gives sorted output 🔹 Why use TreeSet? ✔ Sorted Data Elements are always in ascending order ✔ No Duplicates Just like other Sets, duplicates are not allowed ✔ Navigable Operations Supports methods like higher(), lower(), ceiling(), floor() 🔹 Key Features ✔ Stores unique elements ✔ Automatically sorts elements ✔ Does NOT allow null values ✔ Slower than HashSet & LinkedHashSet (due to sorting) 🔹 Important Methods ✔ add() ✔ remove() ✔ contains() ✔ first() / last() ✔ higher() / lower() 🔹 When should we use TreeSet? 👉 Use TreeSet when: ✔ You need sorted data ✔ You want range-based operations ✔ You need navigation (greater/smaller elements) 🔹 When NOT to use? ❌ When order doesn’t matter → use HashSet ❌ When insertion order matters → use LinkedHashSet ❌ When performance is critical (faster ops needed) 🔹 Key Insight 💡 TreeSet is like a self-sorting set — 👉 You don’t sort the data, it sorts itself automatically 🔹 Day 56 Realization 🎯 Data structures are not just about storing data… 👉 they define how efficiently you can retrieve, organize, and use it #Java #TreeSet #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day56 Grateful for guidance from, Sharath R TAP Academy
To view or add a comment, sign in
-
-
🚀 HashSet in Java Collections Continuing my journey into Set-based collections, I explored HashSet, one of the most widely used data structures for storing unique elements efficiently. 🔹 What is HashSet? HashSet is a class in the Java Collections Framework that stores unique elements. It does not maintain insertion order. Internally backed by a HashMap (Hash Table). 🔹 Key Properties ❌ No insertion order (unordered) ❌ No duplicates allowed ✅ Allows only one null value ✅ Supports heterogeneous data ✅ Fast operations using hashing 🔹 Internal Working Uses Hashing mechanism Data stored in buckets (HashMap structure) Performance depends on: hashCode() equals() 👉 Important: To avoid duplicates, Java uses: hashCode() → to locate bucket equals() → to compare objects 🔹 Constructors HashSet() HashSet(int capacity) HashSet(Collection c) HashSet(int capacity, float loadFactor) ⭐ 👉 Default load factor = 0.75 (important for performance tuning) 🔹 Important Methods add(E e) remove(Object o) contains(Object o) size() isEmpty() clear() iterator() forEach() 🔹 Traversal (Accessing Elements) For-each loop Iterator Stream (Java 8) ❌ No indexing → Traditional for loop not applicable ListIterator not supported 🔹 Performance Add / Remove / Search → O(1) (average) Very fast for lookup operations 🔹 When to Use HashSet? When uniqueness is required When order is not important When you need fast searching/filtering Removing duplicates from collections 🔥 Key Difference (HashSet vs List) HashSet → No order, no duplicates List → Maintains order, allows duplicates 🔹 Learning Outcome Strong understanding of Set behavior Clear idea of hashing & performance Importance of equals() & hashCode() Choosing correct DS based on requirement 🙌 Special thanks to the amazing trainers at TAP Academy: kshitij kenganavar Sharath R MD SADIQUE Bibek Singh Vamsi yadav Hemanth Reddy Harshit T Ravi Magadum Somanna M G Rohit Ravinder TAP Academy Grateful to Tap Academy for strengthening my core Java and data structure concepts 🚀 #TapAcademy #Week13Learning #CoreJava #CollectionsFramework #HashSet #DataStructures #JavaFundamentals #LearningByDoing #FullStackJourney #VamsiLearns
To view or add a comment, sign in
-
-
Day 33 of learning Java! Today I learned about Set & Map Interface + Internal Working (Hashing) 🔹 Set Interface Stores unique elements only No duplicates allowed ✔ Use case: user IDs, emails, unique data 🔹 Internal Working ✔ Set is internally backed by Map • HashSet → uses HashMap ✔ When we add element: • Stored as key • Value = dummy object (PRESENT) 🔹 Hashing Concept 👉 Data stored using: hashCode() → bucket index ✔ Steps: hashCode generated index = hash % n stored in bucket 🔹 Collision Handling 👉 When multiple elements go to same bucket ✔ Java uses: • Linked List (initially) • Red-Black Tree (if large) 🔹 Map Interface 👉 Stores data in key-value pairs ✔ Key → unique ✔ Value → can be duplicate 🔹 Types of Implementations 1. HashMap / HashSet • Fast (O(1)) • No order guarantee 2. LinkedHashMap / LinkedHashSet • Maintains insertion order • Uses doubly linked list 3. TreeMap / TreeSet • Sorted data • Uses Red-Black Tree • Time: O(log n) special thanks to Aditya Tandon and Rohit Negi sir
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