Collections 1 - Questions

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Collections 1 - Questions as PDF for free.

More details

  • Words: 1,390
  • Pages: 8
Collections 1

Questions

Question 1 Which implementation of the List interface produces the slowest access to an element in the middle of the list by means of an index? a. b. c. d.

Vector ArrayList LinkedList None of the above

Question 2 import java.util.*; class A { public static void main (String args[]) { AbstractList a1 = new LinkedList(); AbstractSet b1 = new TreeSet(); AbstractMap c1 = new TreeMap(); System.out.print((a1 instanceof Collection)+","); System.out.print((b1 instanceof Collection)+","); System.out.print(c1 instanceof Collection); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 3 • • • •

Each element must be unique. Duplicate elements must not replace old elements. Elements are not key/value pairs. Accessing an element can be almost as fast as performing a similar operation on an array.

Which of these classes provides the specified features? a. b. c. d. e. f. g. h.

LinkedList TreeMap TreeSet HashMap HashSet LinkedHashMap Hashtable None of the above

Question 4 import java.util.*; class B { public static void main (String args[]) { AbstractMap a1 = new HashMap(); AbstractList b1 = new ArrayList();

page:1

Collections 1

Questions

AbstractSet c1 = new HashSet(); System.out.print((a1 instanceof Collection)+","); System.out.print((b1 instanceof Collection)+","); System.out.print(c1 instanceof Collection); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 5 • •

Entries are organized as key/value pairs. Duplicate entries replace old entries.

Which interface of the java.util package offers the specified behavior? a. b. c. d.

List Map Set None of the above

Question 6 import java.util.*; class D { public static void main (String args[]) { AbstractSet a = new HashSet(); System.out.print((a instanceof Set)+","); System.out.print(a instanceof SortedSet); }} What is the result of attempting to compile and run the program? a. b. c. d. e.

Prints: false,false Prints: false,true Prints: true,false Prints: true,true None of the above

Question 7 Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list? a. b. c. d.

Vector ArrayList LinkedList None of the above

Question 8

page:2

Collections 1

Questions

import java.util.*; class E { public static void main (String args[]) { AbstractSet a1 = new TreeSet(); System.out.print((a1 instanceof Set)+","); System.out.print(a1 instanceof SortedSet); }} What is the result of attempting to compile and run the program? a. b. c. d. e.

Prints: false,false Prints: false,true Prints: true,false Prints: true,true None of the above

Question 9 • • •

Stores key/value pairs. Duplicate entries replace old entries. Entries are sorted using a Comparator or the Comparable interface.

Which of these classes provides the specified features? a. b. c. d. e. f. g.

LinkedList TreeMap TreeSet HashMap HashSet Hashtable None of the above

Question 10 import java.util.*; class F { public static void main (String args[]) { LinkedList a1 = new LinkedList(); ArrayList b1 = new ArrayList(); Vector c1 = new Vector(); System.out.print((a1 instanceof List)+","); System.out.print((b1 instanceof List)+","); System.out.print(c1 instanceof List); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 11

page:3

Collections 1 • •

Questions

Entries are not organized as key/value pairs. Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior? a. b. c. d.

List Map Set None of the above

Question 12 import java.util.*; class G { public static void main (String args[]) { Object a = new HashSet(); Object b = new HashMap(); Object c = new Hashtable(); System.out.print((a instanceof AbstractCollection)+","); System.out.print((b instanceof AbstractCollection)+","); System.out.print(c instanceof AbstractCollection); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 13 • • •

Elements are not key/value pairs. Duplicate elements are not accepted. The entries can be sorted using the Comparable interface.

Which of these classes provides the specified features? a. b. c. d. e. f. g.

LinkedList TreeMap TreeSet HashMap HashSet Hashtable None of the above

Question 14 import java.util.*; class H { public static void main (String args[]) { Object a = new HashSet(); Object b = new HashMap(); Object c = new Hashtable();

page:4

Collections 1

Questions

System.out.print((a instanceof Map)+","); System.out.print((b instanceof Map)+","); System.out.print(c instanceof Map);

}}

What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 15 • • • •

Stores key/value pairs. Allows null elements, keys, and values. Duplicate entries replace old entries. Entries are not sorted.

Which of these classes provides the specified features? a. b. c. d. e. f. g.

LinkedList TreeMap TreeSet HashMap HashSet Hashtable None of the above

Question 16 import java.util.*; class I { public static void main (String args[]) { Object a = new HashSet(); Object b = new HashMap(); Object c = new Hashtable(); System.out.print((a instanceof Cloneable)+","); System.out.print((b instanceof Cloneable)+","); System.out.print(c instanceof Cloneable); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

page:5

Collections 1

Questions

Question 17 • • •

Entries are not organized as key/value pairs. Generally accepts duplicate elements. Entries may be accessed by means of an index.

Which interface of the java.util package offers the specified behavior? a. b. c. d.

List Map Set None of the above

Question 18 import java.util.*; import java.io.Serializable; class J { public static void main (String args[]) { HashMap a = new HashMap(); boolean b1, b2, b3; b1 = (a instanceof Cloneable) & (a instanceof Serializable); b2 = (a instanceof Map) & (a instanceof AbstractMap); b3 = a instanceof Collection; System.out.print(b1 + "," + b2 + "," + b3); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 19 Which of the following classes allow unsynchronized read operations by multiple threads? a. b. c. d. e. f.

Vector Hashtable TreeMap TreeSet HashMap HashSet

Question 20 • • •

Entries are organized as key/value pairs. Duplicate entries replace old entries. Entries are sorted using a Comparator or the Comparable interface.

Which interface of the java.util package offers the specified behavior?

page:6

Collections 1 a. b. c. d. e. f.

Questions

List Map Set SortedSet SortedMap None of the above

Question 21 import java.util.*; class A { public static void main (String[] args) { Object m = new LinkedHashMap(); System.out.print((m instanceof Collection)+","); System.out.print((m instanceof Map)+","); System.out.print(m instanceof List); }} What is the result of attempting to compile and run the program? a. b. c. d. e. f. g. h. i.

Prints: false,false,false Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

Question 22 • • •

Entries are not organized as key/value pairs. Duplicate entries are rejected. Entries are sorted using a Comparator or the Comparable interface.

Which interface of the java.util package offers the specified behavior? a. b. c. d. e. f.

List Map Set SortedSet SortedMap None of the above

Question 23 import java.util.*; class F { public static void main (String[] args) { Object v = new Vector(); System.out.print((v instanceof Collections)+","); System.out.print((v instanceof Arrays)+","); System.out.print(v instanceof List); }} What is the result of attempting to compile and run the program? a. Prints: false,false,false

page:7

Collections 1 b. c. d. e. f. g. h. i.

Questions

Prints: false,false,true Prints: false,true,false Prints: false,true,true Prints: true,false,false Prints: true,false,true Prints: true,true,false Prints: true,true,true None of the above

page:8

Related Documents

Collections Questions
November 2019 13
Collections 1 - Questions
October 2019 11
Collections 2 - Questions
October 2019 22
Collections 1
November 2019 11
Collections 1
November 2019 11