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 list):Prints all the elements in the list.

subList(ArrayList list, int fromIndex, int toIndex): Creates a subList with the fromIndex and toIndex. Also print the subList

findIndex(ArrayList list, String book): 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.

removeItem(ArrayList list, String book) : 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.

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 bookNames = new ArrayList();

//Prints all the elements in the list.

private static void displayList(ArrayList list) {

//Implement

}

//Creates a subList with the fromIndex and toIndex. Also print the subList

private static void subList(ArrayList list, int fromIndex, int toIndex) {

//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 list, String book) {

//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 list, String book) {

//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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!