I'm stuck on a problem where I want multiple user inputs in an array. But the size of the array is not known. What I am trying to do is that assigning the size of the array equal to the number of input entered by the user. And I don't want to ask the user that "Enter the number of inputs u wanna enter".
Asked
Active
Viewed 30 times
0
-
3"*But the size of the array is not known.*" - The size of an array is always known in Java. In fact, that is your problem: the array size is fixed. I would encourage you to use a [`List`](https://docs.oracle.com/javase/9/docs/api/java/util/List.html) instead. – Turing85 Jan 06 '18 at 13:49
-
Consider using dynamically expanding array e.g. ArrayList – Ivaylo Strandjev Jan 06 '18 at 13:50
-
@IvayloStrandjev: which Turing already stated above in the more general sense. – Hovercraft Full Of Eels Jan 06 '18 at 13:50
-
ArrayList is a specific implementation that provides constant access just like a static array, thus I believe it answers the question better than the generic suggestion about List. Depending on what OP will next do with the container, this may be important – Ivaylo Strandjev Jan 06 '18 at 14:19