public static ArrayList<String> fix(ArrayList<String> strings) {
Iterator<String> iterator = strings.iterator();
while(iterator.hasNext()) {
String string = iterator.next();
if (!string.contains("л") && string.contains("р")) {
iterator.remove();
} else if (string.contains("л") && !string.contains("р")) {
String string2 = string.replace("л", "лл");
int index = strings.indexOf(string);
if (index != -1) {
strings.set(index, string2);
}
}
}
return strings;
}
package com.javarush.task.jdk13.task07.task0716;
import java.util.ArrayList;
import java.util.Iterator;
/*
Р или Л
*/
public class Solution {
public static void main(String[] args) {
ArrayList<String> strings = new ArrayList<String>();
strings.add("роза");
strings.add("лоза");
strings.add("лира");
strings = fix(strings);
for (String string : strings) {
System.out.println(string);
}
}
public static ArrayList<String> fix(ArrayList<String> strings) {
Iterator<String> iterator = strings.iterator();
while(iterator.hasNext()) {
String string = iterator.next();
if (!string.contains("л") && string.contains("р")) {
iterator.remove();
} else if (string.contains("л") && !string.contains("р")) {
String string2 = string.replace("л", "лл");
int index = strings.indexOf(string);
if (index != -1) {
strings.set(index, string2);
}
}
}
return strings;
}
}