An Array of unlimited Size, ended by user input "-1"
I need an Array that has unlimited user input but is ended by the user entering a value. The information can be accessed such as how many times a number was entered and what numbers were entered when it is later tabulated and printed to screen
VulpesPosted Dec 10, 2014, 7:03 AM
This doesn't actually resize the current array object, whose size is fixed once created. It simply creates a new array object and then copies the existing array elements to it leaving the old object to be garbage collected in due course. So, it's hardly the most efficient of procedures.
As Manish suggested, a more efficient approach would be to use an ArrayList or generic List for this exercise as these automatically increase their size as needed. Although internally they use an array as their backing store and resize it as needed, resizings are not very frequent. This is achieved by starting with a capacity of 4 and then, when the fifth element is added, doubling the capacity to 8 and so on. The drawback, of course, is that as more and more elements are added you may end up with quite a large amount of unused capacity.
Manish Kumar ChoudharyPosted Dec 10, 2014, 6:37 AM
i don't think it's possible in case of array u can use list or generic for this.