Using algs4.jar from http://algs4.cs.princeton.edu/code/
this code is slow (1000 secs for reading a 8 MB file, runtime grows log2arithmic with file size):
In synfile = new In(filename);
Bag<String> synlines = new Bag<String>();
while (synfile.hasNextLine())
synlines.add(synfile.readLine());
but this is fast (1-2 sec):
In synfile = new In(filename);
ResizingArrayStack<String> synlines = new ResizingArrayStack<String>();
while (synfile.hasNextLine())
synlines.push(synfile.readLine());
However both of the codes are fast when run from opsystem command-line.
The main difference is Bag uses a private Node class and creates a new one in each add() operation, ResizingArray doesn't.