I imagine that the task does not validate because I have a logic error but I do not understand which one.
besides I do not understand pk I needed to use Collections.reverse to have the expected return.
package fr.codegym.task.task07.task0716;
import java.util.*;
/*
R ou L
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> liste = new ArrayList<String>();
liste.add("rose"); // 0
liste.add("love"); // 1
liste.add("lyre"); // 2
liste = corriger(liste);
for (String s : liste) {
System.out.println(s);
}
}
public static ArrayList<String> corriger(ArrayList<String> liste) {
ArrayList<String> listeCorriger = new ArrayList<String>();
for(String s : liste){
if (s.contains("r") && s.contains("l")) {
listeCorriger.add(s);
} else if (s.contains("r")) {
//liste.remove(s);
} else if (s.contains("l")) {
listeCorriger.add(s);
listeCorriger.add(s);
} else {
}
}
Collections.reverse(listeCorriger);
return listeCorriger;
}
}