Parambir.in

Things I Came Across…

Using StringReader to iterate over a String

without comments

StringReader makes it quite convenient to iterate over a string character by character as follows:

StringReader reader = new StringReader("This is a string.");
int ch;
while((ch = reader.read()) != -1)
{
System.out.println((char)ch);
}

Written by Param

March 12th, 2010 at 3:27 pm

Posted in Java

Tagged with

Leave a Reply