Aditya Kanitkar wrote:
Currently, I do not have any Synchronized method in my code.
ganesh roti wrote:Note that ArrayList is position based while vector is both position and hash based. So you can conside Vectoris made up of both the features of a LinkedList and ArrayList.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
ganesh roti wrote:to identify the key difference that you can remove or get the element directly on the index in case of Vector while this is not true in case of arraylist.
Tim Holloway wrote:You can do all of this and more without hashing, although the time it takes is proportional to the size of the Vector.
Mike Simmons wrote:
You can remove or get an element directly in an ArrayList, almost exactly the same way you can in a Vector. There is no substantial difference between the two, except that Vector is synchronized and ArrayList isn't. Both use an internal array, and resize it when necessary. Neither uses hashing. They both have an extremely fast get() method (faster even than hashing) and a comparatively slow remove() method. You can look at the source code for both to see for yourself in the file src.zip, or using whatever IDE you prefer.
Mike Simmons wrote:To clarify, that's true for the remove(), but not the get(). For get() the time is O(1) in a Vector or ArrayList.
Aditya Kanitkar wrote:But didn't get you on this one...
Mike Simmons wrote:
Tim Holloway wrote:"get" is simply the same thing as array indexing in the underlying object array inside the Vector. "remove" moves all higher elements in the Vector down one slot, and shortens the internal array by 1.
You can do all of this and more without hashing, although the time it takes is proportional to the size of the Vector.
To clarify, that's true for the remove(), but not the get(). For get() the time is O(1) in a Vector or ArrayList.
ganesh roti wrote:I am not getting why you are insiting that ArrayList is also not hash based.
ganesh roti wrote:If it is not hash based then why ArrayList is faster than LinkedList in case of retrival?
ganesh roti wrote:To make its object postion based, ArrayList has to create something like a map inside to keep the pointers for the positions. So isn't that similar to hashing(Key, value)?
ganesh roti wrote:And dont mind if i add as i have seen sometimes vectors run fast than Hashmap if you are using Vector as a key value like we do in Hashmap
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|