What would be the closest thing to a std::vector in Java? By this I mean, a class which can take in T into its constructor and then pushBack, popBack() and that is stored in continuous memory (not linked list).
Thanks
The java. util. vector. equals(Object obj) method of Vector class in Java is used verify the equality of an Object with a vector and compare them.
“c++ vector push_back equivalent in java” Code Answer // pop_back equivalent.
Vector implements a dynamic array which means it can grow or shrink as required. Like an array, it contains components that can be accessed using an integer index.
Vector class is often considered as obsolete or “Due for Deprecation” by many experienced Java developers. They always recommend and advise not to use Vector class in your code. They prefer using ArrayList over Vector class.
ArrayList
Everything's stored in array ("contiguous memory") internally, although operation names are a bit different.
A bit more about list implementations in Java
And about generics
edit
Helper Method also mentioned useful class in his answer (although not exactly equivalent to C++ Vector).
That would probably be ArrayDeque, if you need Stack functionality.
Do not use the Stack class as other here suggest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With