Reputation: 5926
I want to change the value and length of a long array during debugging.
For e.g. in my code
long[] longArray = returnLongArray();
Now i want to change the value of longArray variable
the contents of longArray is [0,0,1,1] but i want to change it to [0,1,2]
please note that i want to change the contents of the long array as well as the length too and also hot swapping the code is not an option as the code is running on production
Through variables view i can go and change each primitive long value of the array but not able to reduce the length of the long array.
best Regards,
Saurav
Upvotes: 1
Views: 1007
Reputation: 5926
This what i did .
I had to directly change the reference which was returned from returnLongArray();
I reduced the array length with longArray = Arrays.copyOf(longArray,3) and then change the values.
Upvotes: 1
Reputation: 15225
You'll have to change the value of the array object itself, to a value like "new type[4]", then edit the entries in the array and change their values also.
Upvotes: 1
Reputation: 64
There are a couple of ways to do this, because you are not clear on which array items you are looking to delete.
Given:
longArray[0] = 0
longArray[1] = 0
longArray[2] = 1
longArray[3] = 1
or
longArray = [0,0,1,1]
The array can be manipulated by:
longArray.splice(1, 1);
resulting in:
longArray = [0,1,1]
The array can be manipulated again with:
longArray[3] = 2;
resulting in:
longArray = [0,1,2]
Upvotes: 1