Unexpected java.util.Scanner behaviour

Is it just me or do others find the following behaviour strange? It seems that in order to break out of the loop in the following, it's necessary to enter some character(s) unparseable as a double. Hitting return *won't* cause it to break:

publicstaticvoid scanInts(String[] args){

Scanner scanner =null;

List<Double> coefficients =new ArrayList<Double>();

double x = Double.NaN;

try{

scanner =new Scanner(System.in);

while(scanner.hasNextDouble()){

double d = scanner.nextDouble();

System.out.println("double=" + d);

coefficients.add(d);

}

System.out.println("Now out of loop");

}

finally{

System.out.println(coefficients);

scanner.close();

}

}

[1404 byte] By [cehjohnson] at [2007-9-30 17:36:21]
# 1
I don't think it's strange; Scanner is supposed to ignore extra whitespace and line breaks are whitespace. You can change this behaviour by setting the delimiter to something else, like:scanner.useDelimiter("[ ]*");
jsalonen at 2007-7-6 14:04:47 > top of Java-index,Administration Tools,Sun Connection...
# 2
Thanks, i'll look into that
cehjohnson at 2007-7-6 14:04:47 > top of Java-index,Administration Tools,Sun Connection...
# 3
GreetingsWhat is the job of the scanner's package? i.e. where is it used?Thanx in advance
tleis at 2007-7-6 14:04:47 > top of Java-index,Administration Tools,Sun Connection...