Skip to content

Commit 96a89e4

Browse files
committed
add solution Syntax task 1227
1 parent 92a5503 commit 96a89e4

File tree

1 file changed

+9
-7
lines changed
  • 1.JavaSyntax/src/com/javarush/task/pro/task12/task1227

1 file changed

+9
-7
lines changed

1.JavaSyntax/src/com/javarush/task/pro/task12/task1227/Solution.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@ public class Solution {
1818

1919
public static void main(String[] args) {
2020
rescueRobots();
21+
printList(cableContents);
2122
emptyGarbageBin();
2223
printList(rescuedRobots);
2324
}
2425

2526
public static void rescueRobots() {
2627
for (int i = 0; i < cableContents.size(); i++) {
2728
Robot robot = cableContents.get(i);
28-
if (robot.getName().equals("Amigo")) {
29-
rescuedRobots.add(robot);
30-
cableContents.remove(robot);
31-
i--;
32-
} else if (robot.getName().equals("Diego")) {
29+
if (robot.getName().equals("Amigo") || robot.getName().equals("Diego")) {
3330
rescuedRobots.add(robot);
3431
cableContents.remove(robot);
3532
i--;
3633
}
3734
}
35+
// List<Robot> list = cableContents.stream()
36+
// .filter(robot -> robot.getName().equals("Amigo") || robot.getName().equals("Diego"))
37+
// .toList();
38+
// cableContents.removeAll(list);
39+
// rescuedRobots.addAll(list);
3840
}
3941

4042
private static void emptyGarbageBin() {
@@ -43,8 +45,8 @@ private static void emptyGarbageBin() {
4345
}
4446

4547
public static void printList(List<Robot> list) {
46-
for (Robot o : list) {
47-
System.out.print(o + " ");
48+
for (Robot robot : list) {
49+
System.out.print(robot + " ");
4850
}
4951
System.out.println();
5052
}

0 commit comments

Comments
 (0)