CORE API / NOTES</>↗Core API26 Jan 2024
Whitespace characters in Java (or programming in general) aren’t just the space ' ' character. It also includes other characters that create some form of space or break in the text. The most common ones include: space ' ' tab '\t' newline '\n' carriage return '\r' form feed '\f'. All these characters fall into the […]
JAVA 8 / NOTES</>↗Java 826 Jan 2024
In Java, you can use the removeIf() method to remove elements from a Set-based in a certain condition. Here’s how you can do it: First, get the entry set from the map. The entry set is a Set<Map.Entry<K,V>>. Then, call removeIf() on this set. The removeIf() method takes a predicate, which is a condition that […]
JAVA 8 / NOTES</>↗Java 825 Jan 2024
You can use putAll() method provided by the Map interface to merge entries of two separate Map objects. The putAll() method copies all the mappings from the specified map to the current map. Pre-existing mappings in the current map are replaced by the mappings from the specified map. Here is a Java code example: package […]
JAVA 8 / NOTES</>↗Java 825 Jan 2024
In Java, the Map interface provides the methods replace() and replaceAll(), which are used to replace existing entries in the map. Replace: replace(K key, V value) is a method that replaces the entry for the specified key only if it is currently mapped to some value. It returns the old value associated with the specified […]
JAVA 8 / NOTES</>↗Java 825 Jan 2024
Beginning from Java 8, the Map interface includes the remove(Object key, Object value) method, which removes the entry for the specified key only if it is currently mapped to the specified value. Here is a Java 8 way of accomplishing this: package org.kodejava.util; import java.util.HashMap; import java.util.Map; public class MapRemoveKeyValueExample { public static void main(String[] […]
JAVA 8 / NOTES</>↗Java 825 Jan 2024
The compute(), computeIfAbsent(), and computeIfPresent() methods introduced in Java 8 provide powerful functionality to modify an existing map in a thread-safe manner. Here’s an example of how you might use each: compute(): Performs the given mapping function to the entry for the specified key. The function is applied even if key is not present or […]