+ 1
Can size of array be changed in java programing language??
Hello coders..! I am facing difficult in a java code...please help me to design a code for manual memory allocation of array in java.
4 Answers
+ 3
By definition an array require its size to be defined during creation.
Otherwise, you're looking at an ArrayList with flexible capacity.
đ Additional info
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
+ 2
Just declare arrays as : int arr[] = {};
Don't give any arraysize in those sqaure brackets. This will help you to enter as many values you want in the array.
+ 1
You cannot change the size of an array in Java. Its memory is fixed on allocation. There is no equvalent of C mrealloc
What you can do is allocate a NEW arrary and copy the old data into it.
+ 1
Your solution won't work Akshay Madrikar. You can no longer add an element to the array if you declare it as empty since arrays in Java are designed to have fixed length upon creation.
https://code.sololearn.com/cCVwyW6sv8l5/?ref=app