我正在尝试读取此模式。。。Scanner.useDelimiter
是什么?
此输入为:
489 490-1;491-1;492-1;493-1;494-1;495-1;496-1;497-1;498-1;499-1;500-1
490 491-1;492-1;493-1;494-1;495-1;496-1;497-1;498-1;499-1;500-1
491492-1;493-1;494-1;495-1;496-1;497-1;498-1;499-1;500-1
492 493-1;494-1;495-1;496-1;497-1;498-1;499-1;500-1
493 494-1;495-1;496-1;497-1;498-1;499-1;500-1
494 495-1;496-1;497-1;498-1;499-1;500-1
495 496-1;497-1;498-1;499-1;500-1
496 497-1;498-1;499-1;500-1
497 498-1;499-1;500-1;
我需要的是将489、490、491放在一个控件数组中,将490、1、491、1(第二列和它们)放在一组中。
我尝试了这个分隔符,但它不起作用:Scanner(readerFile).useDelimiter("[^0-9]+");
因为他在我的while(readerFile.hasNextInt())
中保持循环,不调用nextLine()
函数,读取集合中的所有输入。
while (readerFile.hasNextLine()){
readerFile.nextLine();
vector[i] = readerFile.nextInt();
while (readerFile.hasNextInt()){
linkedList.add(reader.nextInt());
}
}
如何控制下一行?
我可能会这样做:
伪码:
While has next line
s = next line
split = s.split(" ", 2);
vector[i] = split[0]; // or whatever you want to do with the first value
values = split[1].split(";")
foreach value in values
linkedList.add(value); // or whatever you want to do with the rest of the values