Question: Need help... Given BookList.java, that creates an ArrayList with 5 elements as below. Java Programming Big Data Programming Algorithms Data Structures Implement the following 4
Need help...
Given BookList.java, that creates an ArrayList with 5 elements as below.
"Java Programming"
"Big Data Programming"
"Algorithms"
"Data Structures"
Implement the following 4 static methods.
displayList(ArrayList
subList(ArrayList
findIndex(ArrayList
removeItem(ArrayList
Sample Output:
Java Programming
Big Data Programming
Algorithms
Data Structures
SubList: [Algorithms, Data Structures]
The index of Java Programming is 0
The Updated List is:[Java Programming, Algorithms, Data Structures]
----------------------------------
import java.util.ArrayList;
public class BookList {
private static ArrayList
//Prints all the elements in the list.
private static void displayList(ArrayList
//Implement
}
//Creates a subList with the fromIndex and toIndex. Also print the subList
private static void subList(ArrayList
//Implement
}
//Check if the given book exists in the list . If exists, find and print the index of the book. Else, print The given book doesn't exist in the list.
private static void findIndex(ArrayList
//Implement
}
//Check if the given book exists in the list. If yes, remove the given book and print the updated list. Else print The given book doesn't exist in the list.
private static void removeItem(ArrayList
//Implement
}
private static void prepareBookList() {
bookNames.add("Java Programming");
bookNames.add("Big Data Programming");
bookNames.add("Algorithms");
bookNames.add("Data Structures");
}
public static void main(String[] args) {
BookList.prepareBookList();
BookList.displayList(bookNames);
BookList.subList(bookNames,2,4);
BookList.findIndex(bookNames, "Java Programming");
BookList.removeItem(bookNames, "Big Data Programming");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
