Java StringReader ClassLast Updated : 29 Jan 2026 Java StringReader class is used to read character data from a string as a character stream. In this chapter, we will learn what the StringReader class is, why it is used, its declaration, constructors, methods, and examples to understand how strings can be processed as character streams. What is StringReader Class in Java?The StringReader class is a character stream that takes a String as its source and converts it into a readable character stream. It extends the Reader class and allows programs to read characters from a string just like reading from a file or other input stream. The StringReader class works completely in memory. It does not use system resources such as files or network sockets, so calling the close() method on a StringReader object has no effect. StringReader Class DeclarationThe StringReader class is a part of the java.io package and extends the Reader class. Constructors of StringReader ClassThe StringReader class provides a constructor to create a character input stream using a string. StringReader(String s)This constructor creates a new StringReader using the specified string as the source of characters. Syntax: It has the following syntax: Example of StringReader Class ConstructorThe following example demonstrates how to create a StringReader object using a string. Methods of StringReader classThe StringReader class provides methods to read characters, skip characters, and manage the reader.
Examples of Java StringReader ClassPractice the following examples to understand the concept and usages of StringReader class. Example 1: Reading Characters from a StringThe following example demonstrates how to read characters from a string using the StringReader class. Output: Hello Java!! Welcome to TpointTech. Example 2: Reading String Data into a Character ArrayThe following example demonstrates how to read string data into a character array using StringReader. Output: Java I/O StringReader Next TopicJava PipedWriter Class |
We request you to subscribe our newsletter for upcoming updates.