First of all I don't understand sense of lines 23-25. And also why wouldn't it work?
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
R or L
1. Create a list of words and populate it yourself.
2. The fix method should:
2.1. remove all words containing the letter "r" from the list
2.2. duplicate all words containing the letter "l".
2.3. if a word contains both "r" and "l", then leave it unchanged.
2.4. don't do anything to other words.
*/
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) {
// write your code here
for(int i=0;i<3;i++){
if (list.get(i).contains("r")&&!(list.get(i).contains("l")))
list.remove(i);
else if (list.get(i).contains("l")&&!(list.get(i).contains("r")))
list.add(list.get(i));
else
;
}
return list;
}
}