我有一个复杂的数据结构(称为twoDim),如下所示
[[Bolus Exposure (Impedance)Upright], [, Recumbent, Total], [, Upright Normal Recumbent Normal Total], [Normal], [Acid Time, 11.0 min, 0.0 min, 11.0 min], ]
[[Acid Exposure (pH), Upright], [Recumbent, Total], [, Upright Normal Recumbent Normal Total], [Normal], [Clearance pH : Channel 7]]
[[Postprandial Data], [, Postprandial Interval: 120 min]]
[[Reflux Study Summary], [Acid Exposure (pH), Upright, Recumbent, Total], [, Upright Normal Recumbent Normal Total], ]]
我只想提取[[Acid Exposure (pH), Upright], [Recumbent, Total], [, Upright Normal Recumbent Normal Total], [Normal], [Clearance pH : Channel 7]]
提取应该基于这样一个事实,即"Recumbent“是一个内部数组中的第一个元素。
我的代码:
ArrayList<ArrayList> AcidExpMain = new ArrayList<ArrayList>();
ArrayList<ArrayList> temp = new ArrayList<ArrayList>();
Pattern tu1 = Pattern.compile("Acid Exposure \\(pH\\)");
Pattern tu2 = Pattern.compile("Recumbent");
for (List<String> row : twoDim) {
if (tu1.matcher(row.get(0)).matches() && tu2.matcher(row.get(0)).matches()) {
AcidExpMain.add((ArrayList<List<String>>) twoDim);
System.out.println("Success");
}
}
然而,我没有捕捉到比赛。如果我单独评估每个匹配语句,它们就会完成各自的工作。那么,我的声明哪里错了呢?
我也试过了
for (List<String> row : twoDim) {
if (tu2.matcher(row.get(0)).matches()) {
temp.add((ArrayList<List<String>>) twoDim);
System.out.println("Success"+temp.size());
for (ArrayList<String> t : temp) {
System.out.println(t+"Success");
if (tu2.matcher(temp.get(0).toString()).matches()) {
AcidExpMain.add((ArrayList<List<String>>) twoDim);
System.out.println("Success");
}
}
}
发布于 2018-08-21 06:01:13
您应该迭代该结构并进行比较。
String[] rows = twoDim.split("[[");
for (String row : rows) {
String[] cols = row.split("[");
然后比较每一列,看看第一个单词是否为“卧式”。
https://stackoverflow.com/questions/36785951
复制相似问题