I have no idea why this is not working?
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.add("dole");
list.add("nice");
list.add("four");
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
// write your code here
for(int i = 0; i < list.size(); i++){//loops over the list
if(list.get(i).contains("r"))
{// if string contains the letter r remove it
list.remove(i);
}
if(list.get(i).contains("l"))
{// if string contains the letter l duplicate it
list.add(list.get(i));
}
if((list.get(i).contains("r")) && (list.get(i).contains("l"))) //||
{
return list;// if string contain r & l don't do anything
}
else
{//if string does not contain r || l don't do anything
return list;
}
}
return list;
}
}