-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeList.java
More file actions
36 lines (25 loc) · 1022 Bytes
/
Copy pathChangeList.java
File metadata and controls
36 lines (25 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package Lists;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class ChangeList {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Integer> numbersList = Arrays.stream(scanner.nextLine().split(" "))
.map(Integer::parseInt).collect(Collectors.toList());
String input = scanner.nextLine();
while(!input.equals("end")){
String command = input.split(" ")[0];
int element = Integer.parseInt(input.split(" ")[1]);
if(command.equals("Delete")){
numbersList.removeAll(Arrays.asList(element));
}else if(command.equals("Insert")){
int index = Integer.parseInt(input.split(" ")[2]);
numbersList.add(index,element);
}
input = scanner.nextLine();
}
System.out.println(numbersList.toString().replaceAll("[\\[\\],]",""));
}
}