java - How to get the array that text belongs in -


i have multidimensional array follows:

[[acid exposure (ph),  upright], [recumbent, total], [,  upright normal recumbent normal total], [normal],] [[bolus exposure (impedance)upright], [,  recumbent, total], [,  upright normal recumbent normal total], [normal]] [[postprandial data], [,  postprandial interval:  120 min]] 

i want create new array if inner array contains line "acid exposure (ph)" end [acid exposure (ph), upright], [recumbent, total], [, upright normal recumbent normal total], [normal],] in new array.

i tried this:

 arraylist<string> matches = new arraylist<string>();  pattern p = pattern.compile("acid exposure \\(ph\\)");       (list<string> row:twodim) {          (string cell:row){             if (p.matcher(cell).matches()) {               matches.add(cell);              system.out.println(matches);             }      }  } 

but gave me [acid exposure (ph)]

you checking if had match in list , add 1 specific item. rather want set flag , add whole list after found match. untested, should this:

// hint, define matches list able change actuall class of list more easy. list<string> matches = new arraylist<string>(); pattern p = pattern.compile("acid exposure \\(ph\\)"); (list<string> row : twodim) {     boolean found = false;     (string cell : row) {         if (p.matcher(cell).matches()) {             system.out.println(matches);             found = true;             // break out of loop, no need check matches anymore             break;         }     }     if (found) {         matches.addall(row);     } } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -