Difference between vector and arraylist | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Difference between vector and arraylist

24th Nov 2016, 4:49 PM
praveen kumar singh
praveen kumar singh - avatar
3 Answers
+ 2
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one Array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. So what is the problems with arrays ? The main problem is that we need to declare the length of array and trying to resize it every time an elements appear it takes time and memory so this is the main problem why arrays are not used in large data or even small data. Another problem is that when you delete an element all other elements before the deleted element must move for one place and this takes time and memory. But they are very good in accessing elements because the elements have indexes so we can easily access an element by its index. ArrayList is different from Array mentioned up . ArrayLists are advanced dataTypes in Java called reference types they are part of java collections so they are build in datatypes. Array List you need to declare them as object and you can also define its datatype known as generics. ArrayList doesnt need to declare its size and it has its own methods like: add,remove,get,size and many others how they are declared Source here: (Java Collections LinkedLists):https://www.sololearn.com/Discuss/100201/how-does-linklist-is-declared-in-java-as-there-is-no-concept-of-pointer-in-java Java Collections in Java Documentation API: https://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html
24th Nov 2016, 8:54 PM
( ͡° ͜ʖ ͡°)
0
The one is thread safe, while the other is not.
24th Nov 2016, 5:25 PM
Miltiadis Siavvas
0
1.Vector is synchronized, slower while ArrayList is not synchronized & faster
24th Nov 2016, 8:01 PM
miche