java


Is it possible to make an array with dynamic memory using while loop without asking the size of memory from user?


I'm trying to make a programme that it doesn't ask user the value i, where i being the number of elements of an array, ( int[] someArray = new int[i]).
Two problems i'm facing , first how the programme auto locates memory size , and second one is, facing trouble with different types of data( i know this one is trivial but just could't put together the logic).
Basically my programme structure is like below:
Scanner input = new Scanner(System.in);
int[] someArray;
int element;
String order;
while(!("done").equals(order=input.nextLine())){
if(some integer){
//set the user input as the value of array element, and change the pointer to the next element
}
if(some string other than "done"){
System.out.println();
//continues the loop
}
}
You can just use an already existing growing collection, such as ArrayList, LinkedList, etc. You add as many elements as you want and they take care of dynamically allocating the necessary space.
This is called dynamic resizing and has the amortized complexity O(n).
The main idea is to double the array size every time your array gets full.
For implementation details I would take a look here.
PS: don't forget to mark some answers for your questions as SOLVED, as it seems that you never do that.

Related Links

Converting a Cloud Storage file into a BigQuery Table/Dataset to then later query
Howto make the withdraw stop when the balance below 25$
getDayOfWeek in ArrayList equals itself, but getYear does not [duplicate]
LWJGL glBufferSubData() is not setting entire array
Getting “This class does not support SAAJ 1.1” when calling SoapMessage.getSOAPBody().hasFault()
magick.MagickException: No image to get image format
Sparks enableHiveSupport
Spring boot UrlFilenameViewController not working
Android Studio & firebase issues
How to design a system which sends records and retries sending them again, if an acknowledgement is not receieved? [closed]
Why is Android Studio able to execute some Git commands, but the UI throws an NPE trying to do a merge?
Control the Mouse and Keyboard from .Net (like java.awt.Robot)
Eclipse Java editor text doesn't appear
How can I pass parameters to second level super class
Regex for matching all words before a specific character
How To Write To Txt File Using If Else Statement Within a Button

Categories

HOME
vim
listview
smarty
sd-card
alfresco
spagobi
spring-cloud-stream
elm
ebean
ojdbc
paradox
maude-system
modelica
collectd
gz
static-libraries
windows-server-2012
after-effects
saxon
tostring
django-cms
firefox-webextensions
conemu
clickonce
jasonette
kvc
android-widget
one-to-many
numerical-methods
intel-pin
linkerd
social-media
libuv
file-rename
nouislider
iframe-resizer
windows-dev-center
wixsharp
suricata
serve
retina-display
mixture-model
theano.scan
hue
bootstrapper
core-plot
nomethoderror
nxlog
gpx
thin
segment
sas-jmp
user-accounts
veracode
tropo
colorama
font-size
mcafee
dwscript
eventkit
topbeat
gridview-sorting
rhino-servicebus
wapiti
phpcas
tcpserver
msys
computer-algebra-systems
deis
interrupted-exception
graph-drawing
createprocessasuser
census
kineticjs
modalpopup
google-style-guide
html-helper
typeof
contenttype
htmlcleaner
srs
mysqltuner
ccss
tws
jplaton
hungarian-algorithm
jquery-mobile-dialog
xamlparseexception
android-screen-support
simba
browser-detection
hamiltonian-cycle
twrequest
parametric-equations
libc++
pydot
data-loss
coercion
sql-server-profiler
coda-slider
brewmp
noscript
scripting-languages
geneva-server
lzh

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App