My code is not working because im guessing that words with only the letter "l" keeps on duplicating without end. What must I do to resolve this?
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("rose"); // 0
list.add("love"); // 1
list.add("lyre"); // 2
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
String s;
int size = list.size();
for(int i = 0; i < size; i++){
s = list.get(i);
if (s.contains("r") && s.contains("l"))
;
else if (s.contains("r")){
list.remove(s);
i--;
}
else if (s.contains("l")){
list.add(s);
}
}
return list;
}
}