java - How do i add data to arraylist by a particular index of array? -
click here pic of arraylists in array java
is possible add arraylists array? , want insert data particular index no of arrray. example, arraylist of array[3]. if isnt possible, how solve in way? writing kmeans clustering in java. adding element particular cluster.
your question not clear, if need create arraylist
of arraylist
's, meaning parent arraylist
other arraylist
's elements use generic types, known templates.
to declare parent array can this, assuming inner child arrays contain int values:
arraylist<arraylist<integer>> arrayofarrays = new arraylist<>();
in order access data 1 of inner child arrays can this:
int value = arrayofarrays.get(3).get(0);
that line return value @ index 0 child array @ index 3. in order add child arrays need use add
method:
arraylist<integer> childarray = new arraylist<>(); arrayofarrays.add(childarray); //adds given array @ last position arrayofarrays.add(1, childarray); //adds given array @ index 1
Comments
Post a Comment