简体   繁体   中英

Changing the value of a long array while eclipse debugging

I want to change the value and length of a long array during debugging.

For eg 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

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]

您必须将数组对象本身的值更改为“ new type [4]”之类的值,然后编辑数组中的条目并更改其值。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM