Computer Science, asked by ashrafkhan4432, 1 year ago

How to declare Java array with array size dynamically?

Answers

Answered by vasantinikam2004
0

In Java, "normal" arrays are fixed-size. You have to give them a size and can't expand them or contract them. To change the size, you have to make a new array and copy the data you want - which is inefficient and a pain for you.

Fortunately, there are all kinds of built-in classes that implement common data structures, and other useful tools too. You'll want to check the Java 6 API for a full list of them.

One caveat: ArrayList can only hold objects (e.g. Integers), not primitives (e.g. ints). In MOST cases, autoboxing/autounboxing will take care of this for you silently, but you could get some weird behavior depending on what you're doing.

Plz mark as brainlist.......


pahalsumit0001: with*
Answered by Oreki
2

An array is a fixed size, homogeneous data structure.

It means that we must specify the number of elements while declaring the array.

But we can use the ArrayList class which is a resizable array, and can be found in the java.util package.

Similar questions