当前位置:网站首页>System.arraycopy的使用和参数含义详解
System.arraycopy的使用和参数含义详解
2022-07-15 10:26:00 【Tan.]der】
官方解释;
1.从指定源阵列从指定位置开始复制阵列到目标阵列的指定位置
2.数组组件的子序列从src引用的源数组复制到dest引用的目标数组
3.复制的组件数量等于length参数
4.将源阵列中srcPos到srcPos+length-1位置的组件分别复制到目标阵列的destPos到destPos+length-1位置
5.如果src和dest参数指向相同的数组对象,那么执行复制操作时,就好像先将srcPos through srcPos+length-1位置的组件复制到带有length组件的临时数组中,然后将临时数组的内容复制到目标数组的destPos through destPos+length-1位置。
6.如果dest为空,则抛出NullPointerException。
7.如果src为空,则抛出NullPointerException,并且不修改目标数组。
8.如果以下任一项为真,则抛出ArrayStoreException,且目标不会被修改:
src参数和dest参数引用组件类型为不同基元类型的数组。
src参数指的是带有原始组件类型的数组,dest参数指的是带有引用组件类型的数组。
src参数指的是带有引用组件类型的数组,dest参数指的是带有原语组件类型的数组。
9.如果以下任何一个为真,则抛出IndexOutOfBoundsException,并且目的地不会被修改:
srcPos论点是否定的。
destPos参数为负。
长度参数是负的。
srcPos+length大于src。Length,源数组的长度。
destPos+length大于目的阵列的长度dest.length。
10.如果源数组从位置srcPos到srcPos+length-1的任何实际组件不能通过赋值转换转换为目标数组的组件类型,则会抛出ArrayStoreException。
11.在这种情况下,让k是小于长度的最小非负整数,以便src[srcPos+k]不能转换为目标数组的组件类型;当抛出异常时,从srcPos到srcPos+k-1位置的源数组组件已经被复制到目标数组位置destPos到destPos+k-1,并且目标数组的其他位置没有被修改。(由于已经列出的限制,这一段实际上只适用于两个数组的组件类型都是引用类型的情况。)
12.形参:
SRC -源阵列。
srcPos—源数组中的起始位置。
Dest -目标阵列。
destPos—目标数据中的起始位置。
length-要复制的数组元素的数量。
13.抛出:
IndexOutOfBoundsException -如果复制会导致访问数组边界之外的数据。
ArrayStoreException -如果src数组中的元素由于类型不匹配而不能存储到dest数组中。
NullPointerException -如果src或dest为空。
简单而言:
System.arraycopy 按参数来说,就是把第一个参数数组中的某一段数据复制到第二个数组中
源码:
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);
src: 原数组
srcPos: 原数组起始位置(从这个位置开始复制)
dest: 目标数组
destPos:目标数组粘贴的起始位置
length: 复制的个数
案例:
public static void main(String[] args) {
int[] arr = {
1, 2, 3, 4, 5};
int[] arr2 = {
5, 6, 7, 8, 9};
System.arraycopy(arr, 1, arr2, 0, 3);
System.out.println(JSON.toJSON(arr2));
}
结果:
[2, 3, 4, 8, 9]
进程已结束,退出代码0
边栏推荐
- 基於機器學習的笑臉檢測
- 030.文件的删除和链接
- Interesting and informative. A cognitive upgrade of zero trust network security architecture
- Dbpack read / write separation function release announcement
- MFC student achievement management system
- JMeter 21 day clock in day03
- QT | vs2017 + qt5.14.2 environment construction
- “天才少年”曹原,共同一作发Nature子刊
- NLP event tutorial for Beihang senior!
- Restore of data encryption returned by a website
猜你喜欢

Sidecar traffic management and multi protocol sniffing in service grid

Smiling face detection based on machine learning

这可是全网网工基础知识最详细的整理,没有之一

002后代选择器
![[leetcode] 522. Longest special sequence II violence + double pointer](/img/37/623ee7f9a039788545572ed9fbeee0.png)
[leetcode] 522. Longest special sequence II violence + double pointer

Axure如何做到屏幕自适应
QT | VS2017 + Qt5.14.2环境搭建

Leetcode - add two numbers

TCP/IP协议常见漏洞类型

002 descendant selector
随机推荐
QT implementation hash table dynamic demonstration
ShareIt group's technology strategy - open, self-supporting and advanced layout
读书的思考
Axure如何做到屏幕自适应
今日睡眠质量记录80分
018. A shielding sensitive vocabulary made by proxy mode knot and filter
Mobile browser product analysis
I would like to ask you guys, how to save the status of this op with Flink SQL
JMeter 21 day clock in day04
Working sql: it is required that the average number of awards cannot be displayed by ranking
003.list!=null和list.size()>0的区别
学习信也杯-train代码学习
Guys, the capture delay of flick CDC Oracle is particularly high. Is there any optimization method
A top-notch book and an ingenious translation! Machine learning and asset pricing is heavily listed
大端字节序和小端字节序
It's time to say goodbye gracefully to nullpointexception
MFC宠物商店信息管理系统
Software testing? Monthly salary 20K +? I can't automate the test. It's really hard for me
Free play noodles
C语言实现贪吃蛇