answersLogoWhite

0


Best Answer

No, you can't change the size of an array dynamically. If you are needing to change the size of an array dynamically use an ArrayList, LinkedList, ConcurrrentHashMap, or another class that meets your needs.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

A dynamic array is an array that that is essentially a list. It's size varies so you may add elements, remove elements, as well as access the elements that already exist within the array. A dynamic array is similar to an array list, but you also may add/remove elements at the beginning, end, and other indices within the array.

Timing Analysis for basic operations:

Insert/Remove start O(n)

Insert/Remove end O(1)

Insert/Remove O(n)

Index Element O(1)

Arrays are implemented using AVL Trees.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

a variable size array in java simply means a VECTOR.

VECTOR is a generic dynamic ARRAY which is variable in size and 'n' number of objects can be created of it.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

They Are used to set the range for our variables.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you change the size of an array dynamically in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


Can array size be increased ones its defined?

Yes but only if it is defined as a pointer and memory is dynamically assigned to the pointer.


How do you determine the size of an array of int passed to a method?

It really depends on the language. In Java, you can use the .length property.


Can arrays be created dynamically?

Yes, arrays can be created dynamically. The following shows how it can be done in C: void f (unsigned n) { int* p = malloc (n * sizeof (int)); /* allocate memory to accommodate n integers */ /* use p... */ free (p); p = 0; }


Is it necessary to give the size of array?

Depends on the language. For C, no you don't. You can type blank brackets (int Arr[]) when declaring the array, or you can just use a pointer (int* Arr). Both will allow you to use the variable as an array without having to declare the specific size. Hope this answers your question. In Java, an array is an object, and one which is dynamically allocated space. The default constructor does not require a size be specified.

Related questions

What is array in structures?

array is used to store the ame datatypes syntex: int array[]=new int[size]; dynamic declaration of array insertion array[1]=20; 2nd way: int array[]={10,20,30}; *important:- int array[20]={20,30,49,....} this way is wrong in java as this is static way and in java all is done dynamically


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


Can array size be increased ones its defined?

Yes but only if it is defined as a pointer and memory is dynamically assigned to the pointer.


How do you determine the size of an array of int passed to a method?

It really depends on the language. In Java, you can use the .length property.


Can arrays be created dynamically?

Yes, arrays can be created dynamically. The following shows how it can be done in C: void f (unsigned n) { int* p = malloc (n * sizeof (int)); /* allocate memory to accommodate n integers */ /* use p... */ free (p); p = 0; }


Is it necessary to give the size of array?

Depends on the language. For C, no you don't. You can type blank brackets (int Arr[]) when declaring the array, or you can just use a pointer (int* Arr). Both will allow you to use the variable as an array without having to declare the specific size. Hope this answers your question. In Java, an array is an object, and one which is dynamically allocated space. The default constructor does not require a size be specified.


Is the array size is fixed after it is created?

Generally, a array is fixed in size. With some libraries, however, they are extensible, either by reallocation/copying strategies (C/C++/STL), or by linking/referencing strategies (JAVA).


What is the method to find size of an array in java?

Arrays have a method called length() that can help us find out the size of the array.int[] l = new int[5];System.out.println(l.length);The above 2 lines of code will create an integer array of size 5 and will print the size 5 on the console.


Why fixed size array is not efficient?

It's not exactly true. Array with fixes size are efficient, but do not work well when you have to resize your array. This actually is the answer for your question. Fixed size arrays are not efficient if you have to change the size. Also you cannot destroy them and release memory used to save the array (for that you have to use operator new).


You can use a variable to declare an array's size true or false?

True and false in the same time, because even so you can declare array size using notation for variables you have use constwhich makes your variable basically a constant:const int arraySize = 10;In Java, you can use any expression to define the array size, when you create the array. Once you create an Array object, however, you can't redimension it - but you can create a new Array object and destroy the old one.


What is ragged array in java?

is an array with more than one dimension each dimension has different size ex: 10 20 30 11 22 22 33 44 77 88


How do you calculate size of an unsized array?

In Java, all arrays have a finite size. Even if you did not initialize an array to a particular size (say the array was being passed into a method), some other part of the program did. Because of this, the length of an array can always be accessed via the .length parameter.Example:int[] arr = new int[5];System.out.print(arr.length); //5public void k(int[] arr){System.out.print(arr.length) //arr will always have a finite size}