
14 CHAPTER 1 Writing a Program
Figure 1.1
Class declaration and
Import statements.
Figure 1.2
The readFromStream
method.
import java.io.*; // for Reader(s), Writer(s),
import java.util.*; // for List, ArrayList, Iterator
public class StringSorter {
ArrayList lines;
public void readFromStream(Reader r) throws
IOException
{
BufferedReader br=new BufferedReader(r);
lines=new ArrayList();
while(true) {
String input=br.readLine();
if(input==null)
break;
lines.add(input);
}
}
1.5.4 Implementation of StringSorter
We will be presenting our implementation followed by the test cases. We are
assuming a certain fundamental background with Java programming,
although familiarity ...