How to scan a string line, then scan inside that line without creating a nested loop? Java -


i want write code scan each line of file, takes each line , scan each next token on (by specified delimiter), compare token input, if there no match moves next line..etc. but, couldn't think of other way doesn't involves making nested loop! there other way, or better approach?

try {     scanner scan = new scanner(clock_time);      while (scan.hasnext()) {         //scan next line         //scan specified tokens each line         //if no match repeat, otherwise break     } } 

use inner loop, that's tool (for life of me, don't know why you're worried using it). sure conserve resources closing inner scanner when you're done after end of inner loop, , same outer scanner.

scanner filescanner = new scanner(somefile); while (filescanner.hasnextline()) {    string line = filescanner.nextline();    scanner innerscanner = new scanner(line);    while (innerscanner.hasnext()) {       // whatever    }    innerscanner.close(); } filescanner.close(); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -