0

Java pass by value in array

i have a array that im changing pretty often and i want to save it everytime in an 2d array. but how i got right now is that the changes apply to every entry in the 2d array and i dont want to do that. i just want a 2d array where i fill a changed array and where every entry is unique. is there a way to do this without creating a new object everytime im changing the array? maybe with arraylist? please without creating a new object or at least not at every entry cause that would be way to much to handle

21st Oct 2017, 8:42 PM
Niklas
Niklas - avatar
4 odpowiedzi
+ 1
arraylist is nice for the fact of dynamic changes and more. However, it also has some issues. Can you elaborate as to why you are using a 2D array and how the storage of the data is? As well, if you could supply some example code, it might help in giving you an answer.
21st Oct 2017, 9:29 PM
Ryan Wakefield
Ryan Wakefield - avatar
0
so i want to use a 2d array because with a string array/arraylist it gave me an out of memory error cause im creating to many new strings but with the string operator so i thought maybe maybe i could make it with a char array. i made an example code but with int array and this shows my Problem pretty good: https://code.sololearn.com/c7GR6U0jUsPQ/?ref=app i hope these Information are enough to come up with a solution
22nd Oct 2017, 8:03 AM
Niklas
Niklas - avatar
0
May I ask what this code is supposed to do? Is it choosing. random number/string? As well, the main reason you would be getting an out of memory exception is because the program is limited to the amount of memory on your computer you are running it on. So this is always something to keep an eye on. Sorry I can't be of much help yet. As I get more clarity, I will be able help more. Thanks.
22nd Oct 2017, 4:20 PM
Ryan Wakefield
Ryan Wakefield - avatar
0
I update your code by this one you can see it https://code.sololearn.com/cT3JsAUSe1Nz/#java
12th May 2020, 4:08 PM
Abdelkhalk Ait Elhaj
Abdelkhalk Ait Elhaj - avatar