0
array
what is the correct way to create an array ? 
4 Antworten
+ 1
in java an array is created as
type[] name;
for example
int[] ages;
but i would recomend arraylists since they are dynamicly resizing whereas arrays are fixed length
arraylist:
ArrayList<type> = new ArrayList<type>(initialSize);
for example
ArrayList<Int> ages = new ArrayList<Int>(50);
to add you do
ages.add(thing)
to remove you do
ages.remove(indexOfThing)
to insert you do
ages.set(index,thing)
!the list needs to already be big enough to put in the item
to get the size you do
ages.size()
and to make sure the array is the big enough you do
ages.ensure(size)
hope this helps
0
is writing a double is right ? or its just string
0
int a[ ]=new int[4];
This will create array of 4 elements starting from 0 indices to 3 indices.