💡 Java Logical Program Practice — Remove Duplicates & Find Largest Numbers 💻 Today I practiced a simple yet powerful Java logic: ✅ Removed duplicate elements from an array using the Set interface ✅ Found the largest and second largest numbers using loops Concepts used: Array sorting (Arrays.sort()) Set for duplicate removal Loop logic for max & second max values Output: Before remove duplicate: [1, 2, 2, 3, 5, 6, 7, 8, 9, 12, 13, 14, 14, 15] After remove duplicate: [1, 2, 3, 5, 6, 7, 8, 9, 12, 13, 14, 15] Largest number: 15 Second largest number: 14 🧠 This kind of daily logic practice strengthens core Java understanding and logical thinking! #Java #CoreJava #CodingPractice #JavaDeveloper #ProgrammingLogic #ProblemSolving #SetInterface #Array #DailyLearning #LearningInPublic
Java Practice: Remove Duplicates, Find Largest Numbers
More Relevant Posts
-
Collection vs Collections in Java — Know the Difference! Collection (Interface) :- It is an interface which should be used when we want to represent a group of individual object then we need to go for collection. 1. Belongs to java.util package 2. It’s the root interface of the Java Collections Framework 3.Implemented by interfaces like List, Set, and Queue 4. All the commonly used method required for all the collection is a part of Collection(I). Collections (Class) :- It is a utility class which defines in java.util which defines utility methods for Collection Objects. 1. Methods like sort(), reverse(), max(), min(), shuffle() #Java #CollectionsFramework #LearningJava #Coding
To view or add a comment, sign in
-
I had this post on my wall today and actually, while really basic, this topic is weirdly interesting. The post mentioned that "a+b is promoted to int" which is not exactly what happens. Actually the operants are converted to "int" before the operation is performed. This is actually the same (and in fact specified) for several languages like Java, C#, C, C++ and for multiple reasons - which are partially decisions made around historic constraints. Newer languages like Rust, Go, Zig, Kotlin, ... don't mirror this and keep the type as specified in the parameters. Back to the example: Java (and also C#) won't do the implicit narrowing to "byte" for strictness and safety reasons, thus the compiler will complain. In C or C++ the implicit narrowing cast is actually done, so the first example compiles just fine "uint8_t c = a + b;". But handling this strictly raises a problem for C# and Java with compount operators. Here the parameters still are promoted to "int" but the specification explicitely states that the behaviour is identical to "E1 = (T)((E1) op (E2))", so a cast is performed. Pretty much solely to support compount operators as syntactic sugar. #Java #CSharp #CPlusPlus #Codingtrivia
Senior Full Stack Java Developer | Spring Boot & Angular | AWS | Certified Professional Scrum Developer I (PSD I®) | Certified Professional Scrum Product Owner I (PSPO I®)
#Java #ProgrammingTips #JavaDevelopment #SoftwareEngineering #ByteShortInt #JavaTricks 𝗝𝗮𝘃𝗮 𝗧𝗶𝗽 : 𝗪𝗵𝘆 𝗯𝘆𝘁𝗲 + 𝗯𝘆𝘁𝗲 𝗯𝗲𝗰𝗼𝗺𝗲𝘀 𝗶𝗻𝘁 𝗯𝘂𝘁 𝗯 += 𝗮 𝘄𝗼𝗿𝗸𝘀 In Java, arithmetic operations on byte and short are automatically promoted to int. • a + b is promoted to int, so assigning it to a byte requires an explicit cast. • b += a is a compound assignment operator. It automatically casts the result back to the type of the left-hand side (byte in this case), so no explicit cast is needed. Understanding this subtlety can save you from unnecessary compilation errors when working with smaller numeric types in Java.
To view or add a comment, sign in
-
-
🚀Day 96/100 #100DaysOfLeetCode 🧩Problem: Reverse Linked List II✅ 💻Language: Java 💡 Approach: 1️⃣ First, use a dummy node to handle edge cases where reversal starts at the head. 2️⃣ Traverse to the node just before the left position — call it prev. 3️⃣ Reverse the sublist between left and right using standard pointer manipulation. 4️⃣ Reconnect the reversed portion back into the original list. 🔑Key Takeaways: 🔹Dummy nodes simplify linked list edge cases. 🔹In-place reversal reduces memory overhead. 🔹Careful pointer tracking ensures list integrity. ⚙️Performance: ⏱️Runtime: 0 ms(beats 100.00%) 💾Memory: 41.29 MB(beats 70.37%) #100DaysOfLeetCode #Java #LinkedList #CodingJourney #ProblemSolving #DSA #LeetCode #CodingChallenge
To view or add a comment, sign in
-
-
🔁 Java DSA Project: Reverse a Linked List#Day5 Built a Java program to demonstrate how to reverse a singly linked list using an iterative approach. This project strengthens understanding of pointers, data structures, and linked list manipulation in Java. ✨ Key Highlights: Custom ListNode class implementation Iterative reversal using prev, curr, and next pointers Simple print function to visualize before & after reversal #Java #DSA #LinkedList #Coding #Algorithms #DataStructures #LearningByCoding
To view or add a comment, sign in
-
-
✨ Difference Between String and StringBuffer In Java, both String and StringBuffer are used to handle text data. However, they differ in mutability, performance, and thread-safety — which makes choosing the right one important for your application. 💡 🧩 1️⃣ String Immutable → Once created, it cannot be changed. Every modification (like concatenation) creates a new object. Slower when performing many modifications. Not thread-safe (since it doesn’t change, this isn’t a problem). ⚙️ 2️⃣ StringBuffer Mutable → Can be modified after creation. Performs operations (append, insert, delete) on the same object. Faster for repeated modifications. Thread-safe → All methods are synchronized. Use String when the content never changes. Use StringBuffer when your program modifies text frequently — especially in multi-threaded applications. Thank you to Anand Kumar Buddarapu Sir for guiding me through this concept and helping me understand Java fundamentals more deeply. #Java #StringVsStringBuffer #CodingBasics #LearningJourney
To view or add a comment, sign in
-
-
💡 Deep Dive into equals() in Java In Java, the equals() method goes beyond comparing memory — it checks meaningful equality. By overriding it, we can define when two objects should be considered the same based on their content, not their reference. In the example below, two Employee objects have identical data but live in different memory locations. Without proper overriding, equals() would return false. Once we customize it to compare id, name, and salary values, both objects are recognized as equal. The string diagram drives this home: == → checks reference 🔗 equals() → checks content 💬 Thanks to Anand Kumar Buddarapu sir for helping us to understand the real use of equals() in Java. #Java #OOPs #equalsMethod #CodingConcepts #JavaDeveloper
To view or add a comment, sign in
-
Day 7/30 — Java + DSA Journey 🚀 Today’s focus was on understanding and working with Strings in Java: ➡ Immutable vs Mutable Strings ➡ StringBuffer (synchronized, thread-safe) ➡ StringBuilder (fast, non-synchronized) ➡ Efficiency in text operations Strings are at the heart of Java programming. Knowing when to use String, StringBuffer, or StringBuilder is key to writing efficient and scalable code. Revising all week’s concepts has solidified the foundation Small steps, consistent progress 🌱 #Java #DSA #Strings #LearnInPublic #CodingJourney
To view or add a comment, sign in
-
Reverse of a number : To reverse a given number in Java, use a loop to extract digits from the number one by one and build the reversed number. Here’s a clear Java program using a while loop, commonly recommended for beginners. import java.util.Scanner; public class ReverseNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number to reverse: "); int number = scanner.nextInt(); int reverse = 0; while (number != 0) { int digit = number % 10; // Get last digit reverse = reverse * 10 + digit; // Shift and add number /= 10; // Remove last digit } System.out.println("Reversed Number: " + reverse); } } Explanation: The loop extracts the last digit using number % 10.It multiplies the reversed number by 10 and adds the extracted digit.The original number is divided by 10 in each iteration to remove the last digit. #JavaProgramming #LearnJava #JavaBasics #CodingChallenge #ProgrammingTips #CodeNewbie #DeveloperLife #100DaysOfCode #JavaDeveloper #SoftwareDevelopment #CodingPractice #TechLearning #ProgrammingCommunity
To view or add a comment, sign in
-
Java Streams have brought a new way to process collections in Java. One standout feature is lazy loading, which is key for writing efficient code. In a stream pipeline, intermediate steps like filter and map do not run immediately. Instead, the computation waits for a terminal operation, such as collect or forEach, to actually start processing the data. This lazy approach means we only process the data when it is really needed and as a result, we save memory and CPU resources. This is especially useful when working with large datasets or building infinite streams. For example, with short-circuiting operations like limit or findFirst, the stream stops as soon as the result is found, making it even more efficient. Lazy loading in streams allows us to create flexible and high-performance data workflows. If you care about resource usage and want to work smarter with data, mastering lazy evaluation in Java Streams is a must. #Java #Streams #LazyLoading #CodingTips #Efficiency #BackendDevelopment #SoftwareEngineering #Programming
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