0

array

what is the correct way to create an array ? 

22nd Jul 2020, 12:15 PM
Blue Monster
Blue Monster - avatar
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
22nd Jul 2020, 12:25 PM
Reece
Reece - avatar
0
is writing a double is right ? or its just string
22nd Jul 2020, 12:17 PM
Blue Monster
Blue Monster - avatar
0
int a[ ]=new int[4]; This will create array of 4 elements starting from 0 indices to 3 indices.
23rd Jul 2020, 1:35 PM
shubham kumar
shubham kumar - avatar