第二个问题,这是第一个问题的继续。我有两个字符串列表。有一个字符串列表 (asu) - M1, M2, M3 ... 以及一个字符串列表 (rzs) - M1, M2, M3 及其所有可能的组合。需要为每个元素(asu)(例如M1)在(rzs)中找到一个元素(M1,M1M2,..),其中包含(例如M1)。示例:从 (asu) 获取 M1 并将开始在 (rzs) 中搜索重复项(包含)。我们在 (rzs) 中找到了 M1M2,它包含 M1。之后,我们应该从列表中删除这两个元素。非常感谢 No Idea For Name 帮助修改了此代码。但是程序总是因为 AbstractList.remove 错误而失败。请帮助实现逻辑和调整代码!
Imports..........
public class work{
List<string> asu = Arrays.asList("M1","M1","M1","M3","M4","M5","M1","M1","M1","M4","M5","M5");
List<string> rzs = Arrays.asList("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(String[] args) {
work bebebe = new work();
bebebe.mywork();
}
List<string> tmp1 = new ArrayList<string>();
List<string> tmp2 = new ArrayList<string>();
System.out.println(Arrays.deepToString(rzs));
System.out.println(Arrays.deepToString(asu));
for (string curr : asu){
for (string currRzs : rzs){
System.out.println("New iteration ");
if (currRzs.contains(curr)) {
System.out.println("Element ("+curr+") in ASU =
element ("+currRzs+") in RZS");
if(tmp1.contains(curr) == false)
tmp1.add(curr);
if(tmp2.contains(currRzs) == false)
tmp2.add(currRzs);
}
}
}
for (string curr : tmp1){
asu.remove(curr);
}
for (string currRzs : tmp2){
rzs.remove(currRzs);
}