Are vectors in c++ the same with arrays in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Are vectors in c++ the same with arrays in java?

I dont know why its called "vectors" but it has the same functions as arrayd in java since they both must be declared with a data type and can only hold values with the same data type they are declared in

30th Aug 2021, 3:49 AM
Mr Cat
Mr Cat - avatar
7 Answers
+ 3
Ipang, No, an array cannot be resized dynamically in java. The size of the array is determined at the time of creation or initialization. It cannot be changed later.
30th Aug 2021, 5:29 AM
Jewel
Jewel - avatar
+ 2
Vectors in C++ are sequence containers representing arrays that can change in size. They use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays https://youtu.be/ryRf4Jh_YC0
30th Aug 2021, 4:00 AM
Vtec Fan
Vtec Fan - avatar
+ 2
Can Java arrays resize (grow or shrink) themselves as necessary? C++ vectors can IIRC.
30th Aug 2021, 4:23 AM
Ipang
+ 2
Yes Martin, That's right, I think it is too. I was just "asking" that to trigger the OP's mind to wonder (and research) whether (as it was asked) C++ vectors were similar to Java arrays.
30th Aug 2021, 1:51 PM
Ipang
+ 1
Simon Sauter why we can't up vote our own questions or posts?? Give me reason ... there is nothing wrong upvoting your own posts Mr Cat u can upvote your own post . there are no rules made for this . it's your own choice
30th Aug 2021, 4:06 AM
Pariket Thakur
Pariket Thakur - avatar
0
HrCoder there are no rules against up voting one's own posts. That doesn't change the fact that it's pathetic. It's like writing a positive review for your own book.
30th Aug 2021, 5:00 AM
Simon Sauter
Simon Sauter - avatar
- 3
Don't up vote your own posts, it's pathetic.
30th Aug 2021, 3:56 AM
Simon Sauter
Simon Sauter - avatar