How do we allocate an array dynamically in java?
An array can be created dynamically with an initializer.
Example:int numbers[] = {1, 2, 4, 8, 16, 32, 64, 128};
This syntax dynamically creates an array and initializes its elements to the specified values.
How do we allocate an array dynamically in java?
1. Arrays in java are static lists that can store a certain kind of variables. Therefore these arrays need to be initialized at the compile time.
2. Though arrays offer efficient performance, they are not space efficient when the data grows to thousands of entries. In this case, it is always a better idea to allocate the memory dynamically. This is where a vector comes into picture.
3. The key difference between Arrays and Vectors in Java is that Vectors are dynamically-allocated.
4. Each Vector can contain a dynamic list of references to other objects. Therefore, they need not contain a single type of variable.
5. The Vector class is found in the java.util package, and extends java.util.Abstractlist