It's my first question here and it's about Java. I would like to implement the following logic:
I have got two string Arrays(or string Lists of string). There is an array of strings (asu) - M1, M2, M3 ... As well as an array of string (rzs) - M1, M2, M3 and all possible combinations thereof. The need for each element (asu) (for example M1) to find an element in (rzs) (M1, M1M2, ..), which contains (e.g. M1). Example: took M1 from (asu) and will start search for duplicate(contain) in (rzs). We found M1M2 in (rzs), it contains M1. After that we should delete both elements from arrays(lists). And I'm sorry for my English skills^^
String[] asu = { "M1", "M1", "M1", "M3", "M4", "M5", "M1", "M1", "M1", "M4", "M5", "M5" };
String[] rzs = { "M1", "M2", "M3", "M4", "M5", "M1M2", "M1M3", "M1M4", "M1M5", "M2M3", "M2M4", "M2M5", "M3M4", "M3M5", "M4M5", "M1M2M3", "M1M2M4",
"M1M2M5", "M1M3M4", "M1M3M4", "M1M4M5", "M2M4", "M2M5" };
public static void main(final String[] args) {
work bebebe = new work();
bebebe.mywork();
}
public void mywork() {
System.out.println(Arrays.deepToString(rzs));
System.out.println(Arrays.deepToString(asu));
for (int i = 0; i < asu.length; i++) {
System.out.println("Итерация: " + i);
for (int j = 0; j < rzs.length; j++) {
if (asu[i].matches(rzs[j].toString())) {
System.out.println(i + " элемент (" + asu[i] + ") в ASU равен " + j + " элементу (" + rzs[j] + ") в RZS");
asu[i] = "";
rzs[j] = "";
}
}
}
}
The result does not delete items that are substring. Does not satisfy logic. I will appreciate your advice.