1

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

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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]

1 Comment

there is no method in java as splice...and also the second approach you mentined will just change the value not the length
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.