Package arraylist1 import javautilLinkedList Publis class Re
Solution
RemoveItemsFromList.java
import java.util.Scanner;
import java.util.LinkedList;
public class RemoveItemsFromList {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
LinkedList<String> list = new LinkedList<String>();
for(;;){
System.out.print(\"Enter the string to add in list (quit to exit): \");
String s = scan.nextLine();
if(s.equalsIgnoreCase(\"quit\")){
break;
}
list.add(s);
}
System.out.println(\"List items are \"+list);
System.out.print(\"Enter the index to delete the item from list: \");
int index = scan.nextInt();
list.remove(index);
System.out.println(\"List items after remove the item are \"+list);
}
}
Output:
Enter the string to add in list (quit to exit): 1
Enter the string to add in list (quit to exit): 2
Enter the string to add in list (quit to exit): 3
Enter the string to add in list (quit to exit): 4
Enter the string to add in list (quit to exit): 5
Enter the string to add in list (quit to exit): quit
List items are [1, 2, 3, 4, 5]
Enter the index to delete the item from list: 3
List items after remove the item are [1, 2, 3, 5]
![Package arraylist1; import java.util.LinkedList; Publis class RemoveFirstLast {public static void main(String[] args) {LinkedList 1List = new LinkedList(); 1Li Package arraylist1; import java.util.LinkedList; Publis class RemoveFirstLast {public static void main(String[] args) {LinkedList 1List = new LinkedList(); 1Li](/WebImages/35/package-arraylist1-import-javautillinkedlist-publis-class-re-1105263-1761584842-0.webp)