Definitely, definitely take the `if` statement out of the loop. People always talk about "the optimizer" but optimizers are different, and whatever you can do to help it is probably a good idea. //Write contents to the file BufferedWriter writer = new BufferedWriter(new FileWriter(file)); for(int i = 0; i < lines.size() - 1; i++) { writer.write(lines.get(i)); writer.newLine(); } // Write the last one without extra newline if( lines.size() ) writer.write(lines.get(lines.size()-1));