java core

Your blog category

Using streams to process collections efficiently.

Using streams in Java allows for efficient and concise processing of collections and other data sources. Streams provide a declarative approach to perform operations on sequences of elements, leveraging functional programming concepts. Operation Traditional Approach Stream API Approach Description Filtering Loop with if condition collection.stream().filter(e -> e.startsWith(“A”)) Filters elements that match a condition. Mapping Loop […]

Using streams to process collections efficiently. Read More »

Implementing custom iterators

Implementing custom iterators in Java involves creating classes that implement the Iterator interface or extend classes that provide iterator functionality (Iterator or ListIterator). Custom iterators are useful when you need to define specialized traversal logic or filter elements during iteration. Let’s create an example of a custom iterator for a list of student names. Implementing

Implementing custom iterators Read More »

Implementing custom collection classes.

Creating custom collection classes in Java involves defining classes that implement the core collection interfaces (List, Set, Map, etc.) or extending existing collection classes to add custom behavior or constraints. Let’s create custom implementations for a List and a Set that store student names, focusing on simplicity and basic functionality. Here’s a simple custom implementation

Implementing custom collection classes. Read More »

Choosing the right data structure based on requirements

1. Understand Your Requirements Criteria Description Data Operations Identify primary operations: insert, delete, search, traversal, etc. Concurrency Will multiple threads access/modify the structure concurrently? Order Is ordering important (sorted, FIFO, LIFO)? Memory Efficiency Is minimal memory usage critical, especially for large datasets? Performance How frequent and large are the operations? Optimize for speed if needed.

Choosing the right data structure based on requirements Read More »

ConcurrentLinkedQueue

ConcurrentLinkedQueue in Java is a concurrent, unbounded queue implementation that provides thread-safe operations for high-performance, scalable handling of elements in a FIFO (First-In-First-Out) manner. It is part of the java.util.concurrent package and is designed for scenarios where multiple threads need to access a queue concurrently without explicit synchronization. The syntax for creating a ConcurrentLinkedQueue is

ConcurrentLinkedQueue Read More »

ConcurrentHashMap

java.util.concurrent.ConcurrentHashMap is a part of the Java Concurrency package and is designed for highly concurrent applications. It is an advanced version of HashMap that allows safe access and modification by multiple threads without the need for external synchronization. Let’s consider a ConcurrentHashMap<String, Integer> that stores the marks of 5 students: Paani, Mahesh, Datta, Ganesh, and

ConcurrentHashMap Read More »

Scroll to Top