+ 1

arrays and their OutOfBounds

Simple arrays are pretty handy, arent they? The only thing that bothers me that they are rigid in their size. Knowing that, I turn to lists. Their functionality in some instatnces is dissapointing for me. What I am supposed to do if I want to create a 2d or 3d array but it must be stretchy? Help please with some ideas. I just want those simple arrays but they must stretch. How'd i do that?

1st May 2017, 4:56 PM
Alex Snaidars
Alex Snaidars - avatar
4 Antworten
+ 10
To add to the size of an array you would need to create a new array with one more size, then do a deep copy of the array. May want to just create a partially filled array instead. ArrayLists work too. You could also use a Linked List.
1st May 2017, 5:14 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
ArrayLists are probably your best bet in Java. Same as arrays, just resizable (to my knowledge). Otherwise, you can try LinkedLists. Best of luck#
1st May 2017, 4:50 PM
Keto Z
Keto Z - avatar
+ 2
@Serena Once I convert a 2d or 3d array to a list, I cannot convert the list back to a 2d or 3d array. Otherwise seems like a fine idea. @Keto Same here
1st May 2017, 5:00 PM
Alex Snaidars
Alex Snaidars - avatar
+ 1
@Serena Oh, that's the lack of experience. I have never seen multidimensional lists so I thought all lists have one dimension only. Something must be added to tutorial materials. Thanks for help ;)
1st May 2017, 5:20 PM
Alex Snaidars
Alex Snaidars - avatar