Remove elements/string objects from HashMap collection by key (Java/example)

HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations like get & put. HashMap based implementation is not thread safe. In multi-threading environment, HashMap should be synchronized externally. If multiple threads access a hashmap concurrently then HashMap must synchronized externally. 1. Methods to remove element or objects from HashMap collection… Read More »

Iterate /loop HashMap collection having string objects (Java8/ example)

1. What is HashMap collection in java? HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations like get & put. HashMap is not not thread safe. HashMap must synchronized externally, If multiple threads access the hashmap concurrently. We will iterate or loop through HashMap collection using following methods: Iterate… Read More »

Add or put elements/string objects to HashMap collection (java /example)

Given a HashMap collection in java, We would like to add or put elements/objects to HashMap. HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations like get & put. HashMap is not not thread safe. HashMap must synchronized externally, If multiple threads access the hashmap concurrently. HashMap collection has… Read More »

File read write operations in java using StringWriter & StringReader (example)

We will discuss file IO operations (read and write) using StringReader and StringWriter. StringWriter is used to give the contents written to it as a String and StringReader is used to read content as a String (using StringReader). We have shown content writing using StringWriter in Fig 1. Program – Read write file in java using StringWriter & StringReader… Read More »

Write file in java using PrintWriter (class hierarchy & example)

PrintWriter writes the formatted data to output stream. PrintWriter provides the methods to write int, boolean, char, String, double, float etc. Constructors of PrintWriter (Java IO) PrintWriter(File file) Creates a new PrintWriter, without automatic line flushing, with the specified file. PrintWriter(File file, String csn) Creates a new PrintWriter, without automatic line flushing, with the specified… Read More »

Read & Write file in java using CharArrayReader & CharArrayWriter (example)

Given the contents, we would like to create or write to file using CharArrayWriter class in java. Read contents from file using CharArrayReader class. 1. CharArrayReader class: CharArrayReader is used to read contents of file as character array. CharArrayReader class has couple of constructors as follows. 2. CharArrayWriter class: CharArrayWrite class is used to write contents as… Read More »