Posts

Showing posts from March, 2024

Quiz

It is possible to employ multiple computer cores to filter a list. Which statement will filter with increased performance? books.parallelStream().filter(book - > { return book.getTitle().startsWith("E"); }).forEach(System.out::println); Correct books.pStream().filter(book - > { return book.getTitle().startsWith("E"); }).forEach(System.out::println); books.streamParallel().filter(book - > { return book.getTitle().startsWith("E"); }).forEach(System.out::println); books.streamp().filter(book - > { return book.getTitle().startsWith("E"); }).forEach(System.out::println); ****************************************************************************************************** Which statement is equivalent to the following code? GreetingMessage gm = new GreetingMessage() { @Override public void greet(String name) { System.out.println("Hello " + name); ...

Java Quize Questions

Q.1 A Queue implements First-In-First-Out(FIFO) data structrure.Which method removes the first element of a list? 1. queue.remove 2. queue.get 3. queue.poll 4. queue.dequeue Ans :- queue.poll Q.2 Collections in Java are an extension of what class? 1.Util 2.Iterable 3.Correct 4.List 5.Interface Ans:- Iterable Q.3 What is a characteristic of an ArrayList? 1.It is faster at removing elements from the middle of a list. 2.It takes up less memory than a linked list. 3.It is harder to implement than a linked list. 4.It is slower at retrieving elements at a particular location. Ans:- It takes up less memory than a linked list. Q.4 What prints to the console after this code executes? LinkedList myList = new LinkedList(); myList.add("A"); myList.add("C"); myList.add(2, "B"); myList.remove("B"); System.out.println(myList); 1. [A, C] 2.[C, A] 3.[A] 4.[C] Ans :- 1. [A, C] Q.5 You create a HashMap data structure using the following stateme...