Problem

The classjava .util .Vector implements a growable array of objects. Here is a subset of th...

The classjava .util .Vector implements a growable array of objects. Here is a subset of the methods available in the classjava. util. Vector:

Constructors

Vector();

// Constructs an empty vector.

Vector(int initialCapacity,int capacitylncrement)

// Constructs an empty vector with the specified // initial capacity and capacity increment.

Methods

void addElement(Object obj);

// Adds the specified component to the end of this // vector, increasing its size by one.

int capacity();

// Returns the current capacity of this vector.

Object elementAt(int index);

// Returns the component at the specified index,void removeElementAt(int index);

// Deletes the component at the specified index, int size();

// Returns the number of components in this vector.

Complete the following tasks:

a. Declare a vectorfirst with an initial capacity of 10 and a capacity increment of 5. Write afor loop that initializes all ten elements of the vector to the integers 1 through 10. What do the methodssize andcapacity return?

b. Add four more integers to the vectorfirst. What do the methods size andcapacity return now?

c. Write a loop to print all of the elements stored in the vectorfirst.

d. Declare a vectorsecond using the default constructor. What doescapacity return in this case? Write a loop to add elements to the vectorsecond so that this capacity is exceeded by one. What is the new capacity?

e. Delete all of the elements from the vectorsecond. Does the capacity change? Why do you think theVector class behaves this way?

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 5
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT