I wrote this method, which is never ending. It isn't printing what I'm passing, why?
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
class Main {
publi开发者_StackOverflow中文版c void readFromConsole() {
ArrayList<String> wholeInput= new ArrayList <String>();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
String line = null;
while (!(line = br.readLine()).equals(" ")){
wholeInput.add(line);
}
}
catch(IOException e){
e.printStackTrace();
}
for (int i =0; i<wholeInput.size();i++){
System.out.println(wholeInput.get(i));
}
}
}
" "
is not an empty line, it is a space. Try ""
while (!(line = br.readLine()).trim().equals("")){
精彩评论