Having issues requuriement 2.2
See comments
Thanks for the help!
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
R or L
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("rrrrrrr"); // 0 - should delete - WORKS FINE
list.add("rl"); // 1 - should keep, has r and l - WORKS FINE
list.add("bob"); // 2 - should keep, all other words - WORKS FINE
list.add("l"); // 3 - should make copy* - PROBLEM.
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
for (int i = 0; i < list.size(); i++) {
if ((list.get(i).contains("r")) && (list.get(i).contains("l"))) {
continue;
} else if (list.get(i).contains("l")) {
String wordCopy = list.get(i);//got the a copy of the word containg "l" and stored it in this var
System.out.println(wordCopy); //print succesfully > the word with l
list.add(wordCopy); // problem here... the could just runs forever... i just wanted one copy lol.
} else if (list.get(i).contains("r")) {
list.remove(i);
}
}
return list;
}
}