Skip to main content

Posts

Showing posts with the label Collection framework

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...

Map interface with implementation classes

Mastering the Java Map Interface and Its Implementation Classes Java Map Interface Architecture Flow Java Map Interface Architecture Flow 1 Identify Associative Data Recognize need for unique key-value lookup in application. 2 Select Map Implementation Choose HashMap, LinkedHashMap, TreeMap, or Hashtable. 3 Execute Map Operations Invoke put(), get(), or remove() using the Map interface contract. 4 Optimize Access Performance Leverage hashing or tree balancing for O(1) or O(log N) lookups. Figure: Java Map Interface Architecture Flow Managing associative data efficiently is a fundamental requirement in enterprise software engineering. When applications need to associate unique identifiers with complex values—such as mapping user IDs to user profiles, tracking configuration properties, or caching compute-heavy results—developers rely on the Java Collections Framework. Specifically, the java.util.Map interface and its concrete implementat...

Set interface in java with example

Mastering the Java Set Interface: Implementation, Performance, and Best Practices Managing collections of unique elements is a fundamental requirement in enterprise software engineering. When your application logic dictates that duplicate values must be automatically rejected—such as tracking active user sessions, unique inventory IDs, or distinct permission roles—standard indexed lists like ArrayList fall short. They allow duplicates and require manual filtering. ▶ Listen English (India) English (US) Hindi Telugu Tamil Kannada Malayalam Bengali Marathi Gujarati Punjabi Urdu Arabic Spanish French German Portuguese Japanese Korean Chinese (Simplified) Pick a language, then press Listen. The java.util.Set interface solves this problem natively. Part of the Java Collections Framework, a Set represents a collection that contains no duplicate elements. This tutorial...

List interface in java with examples

Introduction to the Java List Interface Java List Interface Workflow Java List Interface Workflow 1 Initialize List Create an ordered sequence using a concrete List implementation. 2 Add Elements Append items dynamically while handling duplicates and null values. 3 Positional Access Retrieve, update, or insert elements using zero-based indices. 4 Service Processing Process list data efficiently within enterprise workloads. Figure: Java List Interface Workflow The java.util.List interface is a foundational component of the Java Collections Framework. It represents an ordered collection—often referred to as a sequence—where elements maintain a precise positional index. Unlike mathematical sets, lists allow duplicate elements and multiple null values, mirroring the behavior of arrays with one critical enhancement: they resize dynamically as items are added or removed. ▶ Listen English (India) English (US) Hindi ...

collection framework in java with example

Introduction to the Java Collection Framework Java Collection Framework Workflow Java Collection Framework Workflow 1 Identify Array Limits Recognize fixed size and lack of utility methods in standard arrays. 2 Initialize Data Input Read object parameters like Employee ID and Name using BufferedReader. 3 Apply JCF Architecture Transition data management from arrays to java.util collections. 4 Abstract Data Structures Leverage dynamic structures like lists, hash tables, and trees. 5 Process Business Logic Focus on application requirements instead of custom data management. Figure: Java Collection Framework Workflow When writing enterprise applications, managing groups of related data objects is a foundational requirement. Historically, Java developers relied on arrays to store and manipulate sets of items. However, standard arrays present strict architectural limitations: they possess a fixed size determined at instantiation, la...