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 »

Interface segregation design principle in java (SOLID & real time example)

Interface segregation principle (ISP) is one of the five principles of SOLID acronym. Interface Segregation Principle states “Clients should not be forced to depend upon interfaces that they do not use.” Client should not have the dependency on the interfaces that they do not use. Let us understand the Interface segregation principle with the help of… Read More »

STL Erase-Remove Idiom in C++ (with example)

In C++ programming paradigm, we extensively use the collection frameworks like STL, Its very common practice to remove element(s) from collection(s) like vector. The common practice is just iterate through the container to remove the desired element. But STL has builtin feature specifically to avoid this situation. Erase-Remove idiom comes in our rescue. Erase-Remove is an… Read More »

Add, remove, retain, sort & important methods of linkedlist (java / example)

The LinkedList class extends AbstractSequentialList and implements the List interface. Given a LinkedList in java containing elements. We will discuss following operations of linkedlist with examples Remove Add Retain Sort Iterate Get Contains And Clear Program – Add, remove, retain, sort etc. methods of linkedlist package org.learn.collection.list.linkedlist; import java.util.Collections; import java.util.LinkedList; import java.util.ListIterator; public class DemoLinkedList… Read More »

Page 20 of 44« First...10...1819202122...3040...Last »