Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.io.CharArrayReader; public class JavaCharArrayReader { public static void main(String[] args) { try { char c[] = { 'J', 'A', 'V', 'A', 'S', 'C', 'A', 'N' }; CharArrayReader charReader = new CharArrayReader(c); int i; while ((i = charReader.read()) != -1) { System.out.print((char) i); } } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
The java.io.CharArrayReader.read() method reads a single character. If the stream ends, it returns -1.
CharArrayReader is an implementation of an input stream that uses a character array as the source. This class has two constructors, each of which requires a character array to provide the data source.