CharArrayReader.read() has the following syntax.
public int read() throws IOException
In the following code shows how to use CharArrayReader.read() method.
/*from ww w.ja va2 s. co m*/ import java.io.CharArrayReader; public class Main { public static void main(String[] args) throws Exception { char[] ch = { 'H', 'E', 'L', 'L', 'O' }; CharArrayReader car = new CharArrayReader(ch); int value = 0; // read till the end of the file while ((value = car.read()) != -1) { char c = (char) value; // print the character System.out.print(c + " : "); // print the integer System.out.println(value); } } }
The code above generates the following result.