CharArrayReader class in java

java.io.CharArrayReader is a class in java programming language. Inside of this class exists 8 public methods. Declaration of this class as follows.

public class java.io.CharArrayReader 
extends java.io.Reader 

CharArrayReader public method

There are following useful methods which is define the inside of java.io.CharArrayReader class.

MethodDescription
void close() It closes the stream and releases any system resources associated with it.
void mark(int readAheadLimit) It marks the present position in the stream.
boolean markSupported() It tells whether this stream supports the mark() operation, which it does.
int read() It reads a single character.
int read(char[] b, int off, int len) It reads characters into a portion of an array.
boolean ready() It tells whether this stream is ready to be read.
void reset() It resets the stream to the most recent mark, or to the beginning if it has never been marked.
long skip(long n) It skips characters.

This reference is belong to javadoc

Public Constructors

There is 2 types of public constructor is defined inside the class, Whose syntax as follows.

public java.io.CharArrayReader(char[])
public java.io.CharArrayReader(char[],int,int)

Example of java.io.CharArrayReader(char[]).

// java program for CharArrayReader example 
import java.io.CharArrayReader;
public class Example
{
    public static void main(String[] args) throws Exception
    {
        char[] charArr = {
            'h' , 'a' , 'p' , 'p' , 'y'
        };
        CharArrayReader reader = new CharArrayReader(charArr);
        // Started read with the first character
        int info = reader.read();
        // Iterate the CharArrayReader value
        while (info != -1)
        {
            // info is form of byte
            // (char)info is printing a character value
            System.out.print((char) info);
            info = reader.read();
        }
        reader.close();
    }
}
Instance of java.io.CharArrayReader class in java
happy


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved