In: Computer Science
In java, please
Create an ArrayListReview class with one data field of ArrayList with the generic type passed to the class. (1 point)
Create a constructor that populate an array list filled with the generic type through inserting new elements into the specified location index-i in the list. (1 point)
Implement mergeSort using a list and recursion. (2 points)
Write the main method to test your program and use System.nanoTime() to find out the speed of each step of your program. (1 point)
Create an ArrayListReview class with one data field of ArrayList with the generic type passed to the class. (1 point)
Create a constructor that populate an array list filled with the generic type through inserting new elements into the specified location index-i in the list. (1 point)
Main.java
import java.util.ArrayList;
//Create an ArrayListReview class with one data field of
ArrayList with the generic type passed to the class. (1
point)
class ArrayListReview<T>
{
// An object of type T is declared
ArrayList<T> arrayList=new ArrayList<>();
//Create a constructor that populate an array list filled with the
generic type through inserting new elements into the specified
location index-i in the list. (1 point)
ArrayListReview(T obj,int index) { this.arrayList .add(index, obj);
} // constructor
public T getObject(int index) { return this.arrayList.get(index);
}
}
// Driver class to test above
class Main
{
public static void main (String[] args)
{
// passing instance of Integer type to generic class
ArrayListReview
ArrayListReview <Integer> arrayListReviewObj = new
ArrayListReview<Integer>(15,0);
System.out.println("Integer type :
"+arrayListReviewObj.getObject(0));
//passing instance of instance of String type to generic class
ArrayListReview
ArrayListReview <String> arrayListReviewObj1 = new
ArrayListReview<String>("This is string",0);
System.out.println("String type :
"+arrayListReviewObj1.getObject(0));
}
}
Output