Skip to main content

Posts

Showing posts with the label collections

Duplicate occurrences of characters in String without Collections

Finding Duplicate Characters in a String in Java Without Collections Technical interviews for Java developer positions frequently test fundamental algorithmic problem-solving skills without relying on standard library abstractions. A classic interview question is identifying duplicate characters, unique characters, or duplicate words within a string without using the Java Collections API (such as HashMap , HashSet , or ArrayList ). While using a hash map provides an optimal $O(N)$ time complexity solution, solving this problem using primitive arrays or string manipulation techniques demonstrates a deeper understanding of memory management, string immutability, and character encoding. ▶ Listen English (India) English (US) Hindi Telugu Tamil Kannada Malayalam Bengali Marathi Gujarati Punjabi Urdu Arabic Spanish French German Portuguese Japanese Korean Chinese (Simplified) ...

How to sort list of objects in java with examples

How to Sort a List of Objects in Java: Complete Guide with Examples Java Object Sorting Workflow Java Object Sorting Workflow 1 Define Custom Class Create domain models with multiple fields like Employee. 2 Identify Sorting Need Determine if natural or custom sorting is required. 3 Implement Comparable Add natural ordering via compareTo() inside the target class. 4 Implement Comparator Create external sorting strategies via compare() methods. 5 Execute Sort Operation Sort the list using Collections.sort() with defined criteria. Figure: Java Object Sorting Workflow Sorting a collection of custom objects is a fundamental operation in enterprise software development. Whether you are generating reports, building REST APIs, or preparing datasets for database insertion, organizing domain models into a deterministic sequence is required. In Java, sorting object lists is handled primarily through two core contracts in the java.util pa...