Java Multiple Choice Questions & Answers on Java.util – ArrayList Class for Freshers

1. Which of these standard collection classes implements a dynamic array?

a) AbstractList
b) LinkedList
c) ArrayList
d) AbstractSet
Answer: c

Explanation: ArrayList class implements a dynamic array by extending AbstractList class.
2. Which of these class can generate an array which can increase and decrease in size automatically?

a) ArrayList()
b) DynamicList()
c) LinkedList()
d) DynamicList()
Answer: a
3. Which of these method can be used to increase the capacity of ArrayList object manually?

a) Capacity()
b) increaseCapacity()
c) increasecapacity()
d) ensureCapacity()
Answer: d

Explanation: When we add an element, the capacity of ArrayList object increases automatically, but we can increase it manually to specified length x by using function ensureCapacity(x);
4. Which of these method of ArrayList class is used to obtain present size of an object?

a) size()
b) length()
c) index()
d) capacity()
Answer: a
5. Which of these methods can be used to obtain a static array from an ArrayList object?

a) Array()
b) covertArray()
c) toArray()
d) covertoArray()
Answer: c
6. Which of these method is used to reduce the capacity of an ArrayList object?

a) trim()
b) trimSize()
c) trimTosize()
d) trimToSize()
Answer: d

Explanation: trimTosize() is used to reduce the size of the array that underlines an ArrayList object.
7. What is the output of this program?
  1.     import java.util.*;
  2.     class Arraylist {
  3.         public static void main(String args[]) {
  4.             ArrayList obj = new ArrayList();
  5.             obj.add("A");
  6.             obj.add("B");
  7.             obj.add("C");
  8.             obj.add(1, "D");
  9.             System.out.println(obj);
  10.         }
  11.     }
a) [A, B, C, D] b) [A, D, B, C] c) [A, D, C] d) [A, B, C] View Answer
8. What is the output of this program?
  1.     import java.util.*;
  2.     class Output {
  3.         public static void main(String args[]) {
  4.             ArrayList obj = new ArrayList();
  5.             obj.add("A");
  6.             obj.add(0, "B");
  7.             System.out.println(obj.size());
  8.         }
  9.     }
a) 0
b) 1
c) 2
d) Any Garbage Value
Answer: c
9. What is the output of this program?
  1.     import java.util.*;
  2.     class Output {
  3.         public static void main(String args[]) {
  4.             ArrayList obj = new ArrayList();
  5.             obj.add("A");
  6.             obj.ensureCapacity(3);
  7.             System.out.println(obj.size());
  8.         }
  9.     }
a) 1
b) 2
c) 3
d) 4
Answer: a

Explanation: Although obj.ensureCapacity(3); has manually increased the capacity of obj to 3 but the value is stored only at index 0, therefore obj.size() returns the total number of elements stored in the obj i:e 1, it has nothing to do with ensureCapacity().
10. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             ArrayList obj = new ArrayList();
  4.             obj.add("A");
  5.             obj.add("D");
  6.             obj.ensureCapacity(3);
  7.             obj.trimToSize();
  8.             System.out.println(obj.size());
  9.          }      
  10.     }
a) 1
b) 2
c) 3
d) 4
Answer: b

Explanation: trimTosize() is used to reduce the size of the array that underlines an ArrayList object.

Related

Multiple Choice Questions and Answers on IaaS of Cloud Computing for Freshers

1. Which of the following is a virtual machine technology now owned by Oracle that can run various operating systems ? a) Vmachinesb) VirtualBoxc) ThoughtPoliced) None of the mentioned Answer: b ...

Multiple choice Questions and Answers on Cloud Computing Stack for Freshers

1. A _______ service provider gets the same benefits from a composable system that a user does. a) CaaSb) AaaSc) PaaSd) All of the mentioned Answer: c Explanation: If you are a PaaS or SaaS servi...

Multiple choice Questions and Answers on Connecting to the Cloud for Freshers

1. Which of the following is one of the property that differentiates cloud computing ?a) scalabilityb) virtualizationc) composabilityd) all of the mentioned Answer: c Explanation: Composability is...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item