Java Generics
Generic methods are a very efficient way to handle multiple datatypes using a single method. This problem will test your knowledge on Java Generic methods. Let's say you have an integer array and a string array. You have to write a single method printArray that can print all the elements of both arrays. The method should be able to accept both integer arrays or string arrays. You are given code in the editor. Complete the code so that it prints the following lines: 1 2 3 Hello World Do
View Solution →Java Comparator
Comparators are used to compare two objects. In this challenge, you'll create a comparator and use it to sort an array. The Player class is provided for you in your editor. It has 2 fields: a name String and a score integer. Given an array of n Player objects, write a comparator that sorts them in order of decreasing score; if 2 or more players have the same score, sort those players alphabetically by name. To do this, you must create a Checker class that implements the Comparator interface, t
View Solution →Java Sort
You are given a list of student information: ID, FirstName, and CGPA. Your task is to rearrange them according to their CGPA in decreasing order. If two student have the same CGPA, then arrange them according to their first name in alphabetical order. If those two students also have the same first name, then order them according to their ID. No two students have the same ID. Hint: You can use comparators to sort a list of objects. See the oracle docs to learn about comparators. Input Forma
View Solution →Java Dequeue
In computer science, a double-ended queue (dequeue, often abbreviated to deque, pronounced deck) is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front (head) or back (tail). Deque interfaces can be implemented using various types of collections such as LinkedList or ArrayDeque classes. For example, deque can be declared as: Deque deque = new LinkedList<>(); or Deque deque = new ArrayDeque<>(); You can find mo
View Solution →Java BitSet
Java's BitSet class implements a vector of bit values (i.e.: false (0) or true (1)) that grows as needed, allowing us to easily manipulate bits while optimizing space (when compared to other collections). Any element having a bit value of 1 is called a set bit. Given 2 BitSets, B1 and B2, of size N where all bits in both BitSets are initialized to 0, perform a series of M operations. After each operation, print the number of set bits in the respective BitSets as two space-separated integers on
View Solution →