𝑫𝒂𝒚 6 𝒐𝒇 𝑴𝒚 𝑱𝒂𝒗𝙖 𝑰𝒏𝙩𝒆𝙧𝒗𝙞𝒆𝙬 𝑷𝒓𝒆𝒑𝒂𝒓𝙖𝒕𝒊𝒐𝙣 𝑱𝒐𝒖𝒓𝒏𝒆𝒚 – 45 𝑫𝒂𝒚𝒔 𝑪𝒉𝒂𝒍𝒍𝒆𝒏𝒈𝒆 Today I focused on 𝙎𝙩𝙧𝙞𝙣𝙜 𝙈𝙚𝙩𝙝𝙤𝙙𝙨, which are essential for text processing, data validation, and real-world backend development. 🔤 𝙈𝙖𝙨𝙩𝙚𝙧𝙞𝙣𝙜 𝙎𝙩𝙧𝙞𝙣𝙜 𝙈𝙚𝙩𝙝𝙤𝙙𝙨 𝙞𝙣 𝙅𝙖𝙫𝙖 Java provides many built-in String methods to perform text operations efficiently. 📌 Commonly Used String Methods ✅ length() → Returns number of characters ✅ charAt(index) → Returns character at specific index ✅ toUpperCase() / toLowerCase() → Changes case ✅ substring(beginIndex, endIndex) → Extracts part of string 📌 Search & Comparison Methods ✅ contains() → Checks if string contains value ✅ equals() → Case-sensitive comparison ✅ equalsIgnoreCase() → Case-insensitive comparison ✅ indexOf() / lastIndexOf() → Finds character position 📌 Modification & Utility Methods ✅ replace() → Replaces characters ✅ trim() → Removes extra spaces ✅ startsWith() / endsWith() → Checks prefix or suffix ✅ isEmpty() → Checks if string is empty 📌 Advanced Useful Methods ✅ concat() → Joins strings ✅ compareTo() → Lexicographical comparison ✅ split() → Splits string into array ✅ toCharArray() → Converts string to char array ✅ valueOf() → Converts object to string 💡 𝙆𝙚𝙮 𝙏𝙖𝙠𝙚𝘼𝙬𝙖𝙮 Mastering String methods helps in: ✔ Data validation ✔ API request handling ✔ Log processing ✔ User input handling ✔ Clean and optimized code 💡 𝙆𝙚𝙮 𝙍𝙚𝙛𝙡𝙚𝙘𝙩𝙞𝙤𝙣 Small built-in methods can save hundreds of lines of code. Learning standard libraries deeply makes development faster and smarter. Consistency > Motivation. #Java #InterviewPreparation #BackendDevelopment #45DaysChallenge #JavaDeveloper #Programming #LearningJourney #SoftwareEngineering #Strings #JavaMethods
Sunil Kumar’s Post
More Relevant Posts
-
🚀 Day 22 of #75DaysofLeetCode LeetCode Problem Solved: Determine if Two Strings Are Close (1657) Another interesting String + Frequency Analysis problem from LeetCode! 🔹 Problem: Two strings are considered close if we can transform one into the other using: 1️⃣ Swap any two characters (rearranging characters). 2️⃣ Transform all occurrences of one character into another existing character and vice versa. We need to determine whether word1 can be converted into word2 using these operations. 💡 Key Insights: To make two strings close, three conditions must hold: ✔️ Both strings must have the same length. ✔️ Both strings must contain the same set of characters. ✔️ The frequency distribution of characters must match after sorting. Why? Because operation 2 allows us to swap character frequencies between existing characters. 💻 Java Solution: import java.util.*; class Solution { public boolean closeStrings(String word1, String word2) { if(word1.length() != word2.length()) return false; int[] freq1 = new int[26]; int[] freq2 = new int[26]; for(char c : word1.toCharArray()) freq1[c - 'a']++; for(char c : word2.toCharArray()) freq2[c - 'a']++; for(int i = 0; i < 26; i++){ if((freq1[i] == 0 && freq2[i] != 0) || (freq1[i] != 0 && freq2[i] == 0)) return false; } Arrays.sort(freq1); Arrays.sort(freq2); return Arrays.equals(freq1, freq2); } } 📊 Complexity Analysis: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Problems like this help strengthen understanding of hashing, frequency counting, and string manipulation, which are common in coding interviews. #LeetCode #DSA #Java #CodingPractice #Algorithms #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
✨ Hello Future Developers! We learned: ✔ What is an Array ✔ Traversing ✔ Searching Now it’s time to arrange elements in order 🔥 ==> What is Sorting? :Sorting means arranging elements in: ➡ Ascending Order (1 → 10) ➡ Descending Order (10 → 1) 1️⃣ Bubble Sort 👉 Repeatedly swaps adjacent elements 👉 Largest element “bubbles” to the end ex: int[] arr = {5, 3, 8, 1}; for(int i = 0; i < arr.length-1; i++){ for(int j = 0; j < arr.length-i-1; j++){ if(arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } for(int num : arr){ System.out.print(num + " "); } ⏱ Time Complexity: O(n²) ✔ Easy to understand ❌ Not efficient for large data 2️⃣ Built-in Sorting (Recommended) Java provides a faster way 👇 ex: import java.util.Arrays; int[] arr = {5, 3, 8, 1}; Arrays.sort(arr); System.out.println(Arrays.toString(arr)); ⏱ Time Complexity: O(n log n) 🔥 Interview Insight 📌 Small array → Any method works 📌 Large data → Use efficient algorithms 📌 Always know time complexity #Java #Arrays #DSA #Coding #InterviewPreparation #LearningJourney
To view or add a comment, sign in
-
-
Day 1 — 100 Days of Code | Solved Two Sum Problem (LeetCode) Today I solved the classic Two Sum problem, one of the most common problems asked in coding interviews. 🧩 Problem https://lnkd.in/g9KcCNRv Given an array of integers nums and an integer target, return the indices of two numbers such that their sum equals the target. Example: nums = [2,7,11,15] target = 9 Output → [0,1] Because: nums[0] + nums[1] = 2 + 7 = 9 💡 My Approach At first, the straightforward idea was: Brute Force Approach Check every pair using two loops Time Complexity → O(n²) But we can optimize it. Optimized Approach (HashMap) Idea: Iterate through the array once For each element calculate the complement complement = target - current number Check if complement already exists in HashMap If yes → solution found Otherwise store current number and index in map This reduces time complexity significantly. 🧠 Complexity Time Complexity → O(n) Space Complexity → O(n) 💻 Java Solution import java.util.HashMap; class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer,Integer> map = new HashMap<>(); for(int i = 0; i < nums.length; i++){ int complement = target - nums[i]; if(map.containsKey(complement)){ return new int[]{map.get(complement), i}; } map.put(nums[i], i); } return new int[]{-1,-1}; } } 📚 Key Learning This problem helped me understand the HashMap + Complement pattern, which is useful in many problems like: Pair Sum Subarray Sum Two Sum variants Excited to continue my #100DaysOfCode journey 🚀 Hashtags #100DaysOfCode #Java #DSA #LeetCode #ProblemSolving #CodingJourney #SoftwareEngineering #BackendDeveloper
To view or add a comment, sign in
-
-
𝗠𝗼𝘀𝘁 𝗔𝘀𝗸𝗲𝗱 𝟯𝟱 𝗝𝗮𝘃𝗮 𝟴 𝗖𝗼𝗱𝗶𝗻𝗴 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 𝗶𝗻 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝘀 Many developers prepare Java theory. But in real interviews, companies often test Java 8 coding using Streams and Lambda expressions. Here are 35 commonly asked Java 8 coding problems 👇 1. Find duplicate elements in a list using Streams 2. Remove duplicates from a list using Streams 3. Find the first non-repeated character in a string 4. Find the frequency of each character in a string 5. Reverse a string using Streams 6. Sort a list of integers using Streams 7. Sort a list of employees by salary using Streams 8. Find the second highest number in a list 9. Find the highest number in a list using Streams 10. Find the minimum number in a list 11. Find even numbers from a list using Streams 12. Find odd numbers from a list using Streams 13. Count numbers greater than a given value 14. Convert a list into a set using Streams 15. Convert a list into a map using Streams 16. Join list of strings into a single string 17. Find the longest string in a list 18. Find the shortest string in a list 19. Group employees by department using Collectors.groupingBy() 20. Count occurrences of each element in a list 21. Partition numbers into even and odd 22. Find duplicate characters in a string 23. Find common elements between two lists 24. Convert list of strings to uppercase 25. Filter employees with salary greater than a given value 26. Get top 3 highest numbers from a list 27. Merge two lists using Streams 28. Check if a list contains duplicate elements 29. Calculate the sum of numbers using Streams 30. Group employees by department and count employees 31. Group employees by department and find highest salary 32. Group employees by department and average salary 33. Group strings by their length 34. Group employees by city 35. Group words by their first character These coding problems test your understanding of: • Stream API • Lambda Expressions • Functional Programming • Data transformation using Streams Master these and you’ll be well prepared for Java backend interviews. If you want 𝗱𝗲𝘁𝗮𝗶𝗹𝗲𝗱 𝗿𝗲𝗮𝗹-𝘄𝗼𝗿𝗹𝗱 𝗮𝗻𝘀𝘄𝗲𝗿𝘀 𝗮𝗻𝗱 𝗰𝗼𝗱𝗶𝗻𝗴 𝗲𝘅𝗮𝗺𝗽𝗹𝗲𝘀 for all these questions, comment “𝗝𝗮𝘃𝗮 𝟴” below. I’ll share 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗮𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀 using 𝗦𝘁𝗿𝗲𝗮𝗺𝘀, 𝗟𝗮𝗺𝗯𝗱𝗮, 𝗮𝗻𝗱 𝗿𝗲𝗮𝗹 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝘀𝗰𝗲𝗻𝗮𝗿𝗶𝗼𝘀 that experienced developers are expected to know. Follow for more insights on 𝗝𝗮𝘃𝗮 | 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 | 𝗠𝗶𝗰𝗿𝗼𝘀𝗲𝗿𝘃𝗶𝗰𝗲𝘀 | 𝗗𝗲𝘃𝗢𝗽𝘀 | 𝗖𝗮𝗿𝗲𝗲𝗿 𝗚𝗿𝗼𝘄𝘁
To view or add a comment, sign in
-
-
Loops work. But they don’t always express intent clearly. That’s where 𝗦𝘁𝗿𝗲𝗮𝗺𝘀 𝗔𝗣𝗜 changed Java. Instead of telling the system how to iterate, you describe what you want. Example: List<String> names = Arrays.asList("Alice", "Bob", "Charlie"); names.stream() .filter(name -> name.startsWith("A")) .map(String::toUpperCase) .forEach(System.out::println); This reads like a pipeline: • Take a collection • Filter it • Transform it • Consume it No explicit loop. No temporary variables. No manual indexing. Streams encourage: • Functional-style thinking • Declarative code • Cleaner data transformation They also introduce: • Lambda expressions • Method references • Lazy evaluation Today was about: • Understanding 𝘀𝘁𝗿𝗲𝗮𝗺() • Difference between intermediate and terminal operations • Writing expressive and readable data pipelines Modern Java isn’t about writing more code. It’s about writing clearer code. #Java #Streams #FunctionalProgramming #CleanCode #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
𝗠𝗼𝘀𝘁 𝗔𝘀𝗸𝗲𝗱 𝟯𝟱 𝗝𝗮𝘃𝗮 𝟴 𝗖𝗼𝗱𝗶𝗻𝗴 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 𝗶𝗻 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝘀 Many developers prepare Java theory. But in real interviews, companies often test Java 8 coding using Streams and Lambda expressions. Here are 35 commonly asked Java 8 coding problems 👇 1. Find duplicate elements in a list using Streams 2. Remove duplicates from a list using Streams 3. Find the first non-repeated character in a string 4. Find the frequency of each character in a string 5. Reverse a string using Streams 6. Sort a list of integers using Streams 7. Sort a list of employees by salary using Streams 8. Find the second highest number in a list 9. Find the highest number in a list using Streams 10. Find the minimum number in a list 11. Find even numbers from a list using Streams 12. Find odd numbers from a list using Streams 13. Count numbers greater than a given value 14. Convert a list into a set using Streams 15. Convert a list into a map using Streams 16. Join list of strings into a single string 17. Find the longest string in a list 18. Find the shortest string in a list 19. Group employees by department using Collectors.groupingBy() 20. Count occurrences of each element in a list 21. Partition numbers into even and odd 22. Find duplicate characters in a string 23. Find common elements between two lists 24. Convert list of strings to uppercase 25. Filter employees with salary greater than a given value 26. Get top 3 highest numbers from a list 27. Merge two lists using Streams 28. Check if a list contains duplicate elements 29. Calculate the sum of numbers using Streams 30. Group employees by department and count employees 31. Group employees by department and find highest salary 32. Group employees by department and average salary 33. Group strings by their length 34. Group employees by city 35. Group words by their first character These coding problems test your understanding of: • Stream API • Lambda Expressions • Functional Programming • Data transformation using Streams Master these and you’ll be well prepared for Java backend interviews. If you want 𝗱𝗲𝘁𝗮𝗶𝗹𝗲𝗱 𝗿𝗲𝗮𝗹-𝘄𝗼𝗿𝗹𝗱 𝗮𝗻𝘀𝘄𝗲𝗿𝘀 𝗮𝗻𝗱 𝗰𝗼𝗱𝗶𝗻𝗴 𝗲𝘅𝗮𝗺𝗽𝗹𝗲𝘀 for all these questions, comment “𝗝𝗮𝘃𝗮 𝟴” below. I’ll share 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗮𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀 using 𝗦𝘁𝗿𝗲𝗮𝗺𝘀, 𝗟𝗮𝗺𝗯𝗱𝗮, 𝗮𝗻𝗱 𝗿𝗲𝗮𝗹 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝘀𝗰𝗲𝗻𝗮𝗿𝗶𝗼𝘀 that experienced developers are expected to know. Follow for more insights on 𝗝𝗮𝘃𝗮 | 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 | 𝗠𝗶𝗰𝗿𝗼𝘀𝗲𝗿𝘃𝗶𝗰𝗲𝘀 | 𝗗𝗲𝘃𝗢𝗽𝘀 |
To view or add a comment, sign in
-
-
🚀 Day 15/30 – Java DSA Challenge 🔎 Problem 68: 232. Implement Queue using Stacks (LeetCode – Easy) Continuing Day 15 with another classic data structure transformation problem — implementing a Queue (FIFO) using only Stacks (LIFO) operations. This problem strengthens: ✅ Understanding of LIFO vs FIFO ✅ Stack manipulation ✅ Reversing order using auxiliary stack ✅ Core data structure fundamentals 🧠 Problem Summary We need to design a queue using only stack operations: push(x) pop() peek() empty() ⚠ Constraint: Only standard stack operations allowed — push, pop, peek, size, isEmpty. 💡 Key Insight Queue → First In First Out (FIFO) Stack → Last In First Out (LIFO) To simulate FIFO using LIFO: 👉 Use two stacks: input stack → for push operations output stack → for pop & peek operations When removing elements: If output stack is empty Transfer all elements from input stack to output stack This reverses order and maintains FIFO 🔄 Approach 1️⃣ Push → Always push into input stack 2️⃣ Pop/Peek → If output stack is empty, transfer elements Then pop/peek from output stack 3️⃣ Empty → Check both stacks ⏱ Complexity Analysis Push: O(1) Pop: Amortized O(1) Peek: Amortized O(1) Space Complexity: O(N) 📌 Concepts Reinforced ✔ Stack behavior ✔ Order reversal technique ✔ Amortized time complexity ✔ Clean data structure design 📈 Learning Reflection Even simple-tagged problems reveal deep structural concepts. Understanding how to simulate one data structure using another builds strong problem-solving foundations — crucial for interviews and system design thinking. ✅ Day 15 Progress Update 🔥 68 Problems Solved in 30 Days DSA Challenge Small daily improvements → Big long-term mastery 🚀 #Day15 #30DaysOfDSA #Java #LeetCode #Stack #Queue #DataStructures #CodingJourney #InterviewPreparation
To view or add a comment, sign in
-
-
🚀 𝗪𝗵𝘆 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻 𝗙𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 𝗜𝗻𝘀𝘁𝗲𝗮𝗱 𝗼𝗳 𝗔𝗿𝗿𝗮𝘆𝘀? Today I revised an important core Java concept. I reflected on an important question: 👉 Why do we prefer the Collection Framework over Arrays in real-world applications? 🔎 𝗔𝗿𝗿𝗮𝘆𝘀 — 𝗦𝗶𝗺𝗽𝗹𝗲 𝗯𝘂𝘁 𝗟𝗶𝗺𝗶𝘁𝗲𝗱 • Fixed size (defined at creation time) • No built-in utility methods • Manual resizing required • Limited flexibility for dynamic data • Homogeneous data Example: int[] arr = new int[3]; Once the size is fixed, it cannot grow. 🚀 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻 𝗙𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 – 𝗙𝗹𝗲𝘅𝗶𝗯𝗹𝗲 & 𝗦𝗰𝗮𝗹𝗮𝗯𝗹𝗲 Java provides powerful data structures through the Collection Framework. Example: ArrayList<Integer> list = new ArrayList<>(); list.add(10); list.add(20); list.add(30); list.add(40); // Automatically resizes ✅ 𝗪𝗵𝘆 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻𝘀 𝗔𝗿𝗲 𝗣𝗿𝗲𝗳𝗲𝗿𝗿𝗲𝗱 • Dynamic resizing • Built-in methods (add(), remove(), contains()) • Multiple data structures: • List → Ordered data • Set → Unique elements • Map → Key-value pairs • Queue → FIFO processing • Better scalability for real-world systems 💡 𝗞𝗲𝘆 𝗜𝗻𝘀𝗶𝗴𝗵𝘁 *Arrays are good for fixed-size data. *Collections are designed for real-world, evolving applications. Understanding why we use something makes us stronger developers — not just coders. #Java #CollectionFramework #Programming #DSA #LearningJourney
To view or add a comment, sign in
-
-
✨ Good day.... Developers! Creating and traversing arrays is important… But how do we find an element inside an array? 🤔 That’s where Searching comes in 🔍 1️⃣ Linear Search (Sequential Search) 👉 Checks each element one by one 👉 Works on both sorted & unsorted arrays int[] arr = {10, 20, 30, 40}; int key = 30; for(int i = 0; i < arr.length; i++){ if(arr[i] == key){ System.out.println("Element found at index: " + i); break; } } ==> ⏱ Time Complexity: O(n) ✔ Simple ✔ Beginner-friendly ✔ No sorting required 2️⃣ Binary Search 👉 Works only on sorted arrays 👉 Divides the array into halves import java.util.Arrays; int[] arr = {10, 20, 30, 40, 50}; int key = 30; int index = Arrays.binarySearch(arr, key); System.out.println("Element found at index: " + index); ==> ⏱ Time Complexity: O(log n) ✔ Faster than linear search ✔ Requires sorted data 🔥 Interview Insight 📌 When array is small → Linear search is fine 📌 When array is large & sorted → Binary search is better 📌 Binary search on unsorted array → ❌ Wrong logic #Java #DSA #Programming #CodingInterview #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
"I’ve been diving deep into Java array manipulations today! 🚀 I worked on a logic challenge where I had to transform an array based on index positions. The goal: keep even-indexed numbers the same, but cube the numbers at odd-indexed positions. The Logic: Input: [1, 2, 3, 4, 5] Output: [1, 8, 3, 64, 5] Program: import java.util.Arrays; public class Main { public static void main(String[] args) { int[] input = {1, 2, 3, 4, 5}; int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { // Check if index is odd (1, 3, 5...) if (i % 2 != 0) { // Logic: Value multiplied by itself three times (cubed) output[i] = input[i] * input[i] * input[i]; } else { // Even index (0, 2, 4...): Keep the same output[i] = input[i]; } } // Printing the output array System.out.println(Arrays.toString(output)); } } #Java #ContnuousLearning #Programming #SoftwareDevelopment #Immediatejoiner
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