Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; public class Main { /** * Reads a sentence from the a reader and returns a string array with tokens. * * The method expect that each line contains a token and empty line is equal to end of sentence. * * There are no check for particular data format so if the input is garbage then the output will also be garbage. * * @param reader a buffered reader * @return a string array with tokens * @throws IOException */ public static String[] readSentence(BufferedReader reader) throws IOException { ArrayList<String> tokens = new ArrayList<String>(); String line; while ((line = reader.readLine()) != null) { if (line.trim().length() == 0) { break; } else { tokens.add(line.trim()); } } return tokens.toArray(new String[tokens.size()]); } }