---
title: "Why is Java Vector class considered obsolete or deprecated?"  
description: "Why is Java Vector class considered obsolete or deprecated?"  
author: "Anonymous User"  
published: 2015-07-10  
updated: 2015-07-10  
canonical: https://www.mindstick.com/forum/23333/why-is-java-vector-class-considered-obsolete-or-deprecated  
category: "java"  
tags: ["java", "collection"]  
reading_time: 2 minutes  

---

# Why is Java Vector class considered obsolete or deprecated?

Isn't its use valid when working with [concurrency](https://www.mindstick.com/interview/23470/what-is-the-concurrency)?\
\
And if I don't want to manually synchronize [objects](https://www.mindstick.com/forum/145447/what-are-objects) and just want to use a thread-[safe](https://www.mindstick.com/articles/126322/how-to-keep-your-home-safe-while-traveling) [collection](https://www.mindstick.com/articles/1718/collections-in-java) without needing to make [fresh](https://www.mindstick.com/articles/13161/10-fresh-marketing-strategies-for-small-business-that-really-work) copies of the underlying [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) (as CopyOnWriteArrayList does), then is it fine to use [Vector](https://www.mindstick.com/forum/33499/vector-vs-arraylist-which-has-better-performance-and-why)?\
What about [Stack](https://www.mindstick.com/blog/301746/why-is-stack-overflow-so-important-for-developers), which is a subclass of Vector, what should I use [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) it?

## Replies

### Reply by Anonymous User

Vector synchronizes on each individual operation. That's almost never what you want to do.\
Generally you want to synchronize a whole sequence of operations. Synchronizing individual operations is both less safe (if you iterate over a Vector, for instance, you still need to take out a lock to avoid anyone else changing the collection at the same time, which would cause a ConcurrentModificationException in the iterating thread) but also slower (why take out a lock repeatedly when once will be enough)?\
Of course, it also has the overhead of locking even when you don't need to.\
Basically, it's a very flawed approach to synchronization in most situations. As MrSpandex pointed out, you can decorate a collection using the calls such as Collections.synchronizedList - the fact that Vector combines both the "resized array" collection implementation with the "synchronize every operation" bit is another example of poor design; the decoration approach gives cleaner separation of concerns.\
As for a Stack equivalent - I'd look at Deque/ArrayDeque to start with.


---

Original Source: https://www.mindstick.com/forum/23333/why-is-java-vector-class-considered-obsolete-or-deprecated

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
