Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent for Java System.arraycopy in Dart?

Tags:

dart

How do I convert the below java code to equivalent dart.

private static final byte[] mIdBytes = new byte[]{(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x7E};

byte[] data;

System.arraycopy(mIdBytes, 2, data, 0, 4);

Is there any Dart method that does a similar kind of operation?

I was looking into this: https://pub.dev/documentation/ckb_dart_sdk/latest/ckb-utils_number/arrayCopy.html

like image 237
Uday Avatar asked Jul 26 '26 22:07

Uday


1 Answers

To match Java's System.arrayCopy(source, sourceOffset, target, targetOffset, length) you should use

 target.setRange(targetOffset, targetOffset + length, source, sourceOffset);

This is more efficient than using List.copyRange for some lists, for example copying between typed-data lists with the same element size (like two Uint8Lists).

like image 165
lrn Avatar answered Jul 28 '26 12:07

lrn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!