Discuss about the Vector Class. "Vector objects cannot store primitive type data directly." — Is it true?

No comments
In java.util package there is an in built class called Vector. It simulates the functionality of a growable array of objects. But the size of the Vector can grow and shrink according to programming needs. The Vector class has several methods like add, remove, size, clear, capacity to support different operations on a group of elements. All the methods of a Vector are synchronized, which means, that they are thread safe. Thread safe methods are useful in concurrent programming. The striking advantage of Vector over an array is that the vector can store elements of different data types. But the programmer should be careful while retrieving elements from such a Vector using proper casting mechanism. Otherwise there is a chance that the retrieval operations will throw a ClassCastException Prior to java 5 the Vector class could not store primitive types like int, char, float, double. In order to store them the programmer would have required converting them to object, using the respective Wrapper classes. Like for int Integer, Character for char etc. But from java 1.5 this is done automatically by the compiler using the newly introduced auto boxing feature.

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀