Всем привет, как создать на вот этот код цикл? Я пробовал по такому типу
for (int i = 0;i < 6;i++){
boolean ai = checkWithRegExp(q1);
boolean bi = checkWithRegExp1(q2);
}
Но результаты безуспешны. Как в цикле задать, чтобы метод тоже менялся? Ставил checkWithRegExpi(qi) . Выдает ошибку.
boolean a1 = checkWithRegExp(q1);
boolean b1 = checkWithRegExp1(q2);
boolean a2 = checkWithRegExp(w1);
boolean b2 = checkWithRegExp1(w2);
boolean a3 = checkWithRegExp(e1);
boolean b3 = checkWithRegExp1(e2);
boolean a4 = checkWithRegExp(r1);
boolean b4 = checkWithRegExp1(r2);
boolean a5 = checkWithRegExp(t1);
boolean b5 = checkWithRegExp1(t2);
//
boolean a6 = checkWithRegExp(q1);
boolean b6 = checkWithRegExp2(q2);
boolean a7 = checkWithRegExp(w1);
boolean b7 = checkWithRegExp2(w2);
boolean a8 = checkWithRegExp(r1);
boolean b8 = checkWithRegExp2(r2);
boolean a9 = checkWithRegExp(e1);
boolean b9 = checkWithRegExp2(e2);
boolean a10 = checkWithRegExp(t1);
boolean b10 = checkWithRegExp2(t2);
//
boolean a11 = checkWithRegExp(q1);
boolean b11 = checkWithRegExp3(q2);
boolean a12 = checkWithRegExp(w1);
boolean b12 = checkWithRegExp3(w2);
boolean a13 = checkWithRegExp(e1);
boolean b13 = checkWithRegExp3(e2);
boolean a14 = checkWithRegExp(r1);
boolean b14 = checkWithRegExp3(r2);
boolean a15 = checkWithRegExp(t1);
boolean b15 = checkWithRegExp3(t2);
//
boolean a16 = checkWithRegExp(q1);
boolean b16 = checkWithRegExp3(q2);
boolean a17 = checkWithRegExp(w1);
boolean b17 = checkWithRegExp3(w2);
boolean a18 = checkWithRegExp(e1);
boolean b18 = checkWithRegExp3(e2);
boolean a19 = checkWithRegExp(r1);
boolean b19 = checkWithRegExp3(r2);
boolean a20 = checkWithRegExp(t1);
boolean b20 = checkWithRegExp3(t2);
Например, можно использовать списки:
public static void main(String[] args) {
List<Pattern> patternList = Arrays.asList(Pattern.compile("reg1"), Pattern.compile("reg2"), Pattern.compile("reg3"), Pattern.compile("reg4"));
List<String> dataList = Arrays.asList("str1", "str2", "str3", "str4");
IntStream.range(0, patternList.size()).forEach(i -> System.out.println(checkWithRegExp(patternList.get(i), dataList.get(i))));
}
private static boolean checkWithRegExp(Pattern pattern, String data) {Matcher matcher = pattern.matcher(data);
return matcher.find();
}
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости