Forums Register Login

Whizlab question on Vector

+Pie Number of slices to send: Send
A Vector maintains object refrences in the order they were added.
ans given is true.
According to me ans should be false because the Vector is ordered by index not by insertion order
+Pie Number of slices to send: Send
Hi there,


According to me ans should be false because the Vector is ordered by index not by insertion order


Isn't the insertion order same as ordered by the index ??
Do clarify?
+Pie Number of slices to send: Send
Mohit,
The method

adds o to the end of the vector.
The method

inserts element at position index, 0<=index<size()
This means that when you add an object to a vector , this is added at
the end, so it maintains the order.
+Pie Number of slices to send: Send
 

Originally posted by Mohit Goyal:
A Vector maintains object refrences in the order they were added.
ans given is true.
According to me ans should be false because the Vector is ordered by index not by insertion order


The wording sounds a bit ambiguous to me. Well, let's see how a Vector maintains order of its elements. There're 3 methods that put a new element at the end of the vector so that the resulting order is in fact the insertion order:

And there're 2 other methods that allow you to insert element(s) at the specified position:

In both cases, the elements are accessible either through their indexes or the iterator() method. If the elements were added using the first group of methods, iterator() returns them in the order they were inserted.
+Pie Number of slices to send: Send
Thanx Vad u really cleared my doubt. i was going through Khalid's book this evening in which it was given that Vector is ordered by insertion order. But I think u r right they ordered by both
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 612 times.
Similar Threads
Is both Vector and Hashtable maintains object references in the order they were added?
questions on java.util package - Part 3
Vector.
About vector
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:07:04.