java arraycopy方法_Java System.arrayCopy()方法
System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制。
其函数原型是:
/**
* Copies an array from the specified source array, beginning at the
* specified position, to the specified position of the destination array.
* A subsequence of array components are copied from the source
* array referenced by src
to the destination array
* referenced by dest
. The number of components copied is
* equal to the length
argument. The components at
* positions srcPos
through
* srcPos+length-1
in the source array are copied into
* positions destPos
through
* destPos+length-1
, respectively, of the destination
* array.
*
* If the src
and dest
arguments refer to the
* same array object, then the copying is performed as if the
* components at positions srcPos
through
* srcPos+length-1
were first copied to a temporary
* array with length
components and then the contents of
* the temporary array were copied into positions
* destPos
through destPos+length-1
of the
* destination array.
*
* If dest
is null
, then a
* NullPointerException
is thrown.
*
* If src
is null
, then a
* NullPointerException
is thrown and the destination
* array is not modified.
*
* Otherwise, if any of the following is true, an
* ArrayStoreException
is thrown and the destination is
* not modified:
*
*
The src
argument refers to an object that is not an
* array.
*
The dest
argument refers to an object that is not an
* array.
*
The src
argument and dest
argument refer
* to arrays whose component types are different primitive types.
*
The src
argument refers to an array with a primitive
* component type and the dest
argument refers to an array
* with a reference component type.
*
The src
argument refers to an array with a reference
* component type and the dest
argument refers to an array
* with a primitive component type.
*
*
* Otherwise, if any of the following is true, an
* IndexOutOfBoundsException
is
* thrown and the destination is not modified:
*
*
The srcPos
argument is negative.
*
The destPos
argument is negative.
*
The length
argument is negative.
*
srcPos+length
is greater than
* src.length
, the length of the source array.
*
destPos+length
is greater than
* dest.length
, the length of the destination array.
*
*
* Otherwise, if any actual component of the source array from
* position srcPos
through
* srcPos+length-1
cannot be converted to the component
* type of the destination array by assignment conversion, an
* ArrayStoreException
is thrown. In this case, let
* k be the smallest nonnegative integer less than
* length such that src[srcPos+
k]
* cannot be converted to the component type of the destination
* array; when the exception is thrown, source array components from
* positions srcPos
through
* srcPos+
k-1
* will already have been copied to destination array positions
* destPos
through
* destPos+
k-1
and no other
* positions of the destination array will have been modified.
* (Because of the restrictions already itemized, this
* paragraph effectively applies only to the situation where both
* arrays have component types that are reference types.)
*
* @param src the source array.
* @param srcPos starting position in the source array.
* @param dest the destination array.
* @param destPos starting position in the destination data.
* @param length the number of array elements to be copied.
* @exception IndexOutOfBoundsException if copying would cause
* access of data outside array bounds.
* @exception ArrayStoreException if an element in the src
* array could not be stored into the dest
array
* because of a type mismatch.
* @exception NullPointerException if either src
or
* dest
is null
.
*/
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);
src:源数组;
srcPos:源数组要复制的起始位置;
dest:目的数组;
destPos:目的数组放置的起始位置;
length:复制的长度。
注意:src and dest都必须是同类型或者可以进行转换类型的数组
java arraycopy方法_Java System.arrayCopy()方法相关推荐
- java arraycopy 参数_java System.arraycopy()复制数组
在数组的复制中,总共有四种方法可以实现.不过在追求效率上,本篇所要提到的System.arraycopy()方法,要比我们熟知的for循环快太多.考虑到这种方法使用不频繁,所以在接下来的学习中,我们先 ...
- java getenv()_Java System getenv()方法
Java System getenv()方法 java.lang.System.getenv(String name) 方法获取指定的环境变量的值.环境变量是依赖于系统的外部命名值. 环境变量应使用一 ...
- java secretkey用法_Java SecretKeyFactory.generateSecret方法代码示例
本文整理汇总了Java中javax.crypto.SecretKeyFactory.generateSecret方法的典型用法代码示例.如果您正苦于以下问题:Java SecretKeyFactory ...
- java arraycopy 并发_java用arraycopy实现多击事件
本文实例为大家分享了java用arraycopy实现多击事件的3种方法,供大家参考,具体内容如下 1.双击事件的实现 我们规定两次点击的事件间隔在500毫秒内为双击事件,这一值可以随意限定. bt_c ...
- java set 包含_Java Set.contains()方法:判断Set集合是否包含指定的对象
Java 集合类中的 Set.contains() 方法判断 Set 集合是否包含指定的对象.该方法返回值为 boolean 类型,如果 Set 集合包含指定的对象,则返回 true,否则返回 fal ...
- java 发送邮件 菜鸟_Java发送邮件的方法
1.需要的jar包 2.具体实现方法 1.设置邮箱主机.需要认证.邮箱协议 Properties pro=new Properties(); pro.setProperty("mail.ho ...
- java show过时_Java中show() 方法被那个方法代替了? java编程 显示类中信
你说的show是swing里的吧,在老版本中Component这个超类确实有show这个方法,而且这个方法也相当有用,使一个窗口可见,并放到最前面.在jdk5.0中阻止了这个方法,普遍用setVisi ...
- java中断响应时间_Java多线程 sleep方法响应中断 sleep面试问题(与wait/notify的
Java多线程 sleep方法响应中断 sleep面试问题(与wait/notify的 Java多线程 sleep方法响应中断 & sleep面试问题(与wait/notify的比较) 文章目 ...
- java中方法_java中的方法
java中的方法 java作为一种面向对象的语言,具有以下特性:继承.封装.多态.抽象.类.对象.实例.方法和重载. 今天讲解的是java方法的概念. 什么是方法? java方法是语句的集合,他们在一 ...
最新文章
- Dubbo 如何成为连接异构微服务体系的最佳服务开发框架
- 【flutter】把Google官方的历史时间demo跑起来
- git cherry-pick
- Symantec NetBackup 7.1 自动刷新磁带脚本
- 中国半导体材料市场投资潜力与发展动态研究报告2022版
- 《古剑奇谭2》详细测评心得
- Meta AI 发布 data2vec!统一模态的新里程碑!
- [CodeForces332E]Binary Key
- 指针和引用的相同与不同
- 7-7自动色阶/自动对比度/自动颜色
- 下载安装配置Pycharm免费版
- 图像处理: AlphaBlend
- 微信小程序拨号功能,调起手机拨号!
- Android开发——监听Android手机的网络状态
- 屏蔽烦人的百度搜索热点
- 西游记中孙悟空大闹天宫时期被孙悟空打败的
- 五、dynamic类型
- matlab 拟合优度检验,卡方拟合优度检验在教学中的应用及Matlab实现_刘泽显
- 教程篇(7.0) 03. FortiGate基础架构 虚拟域(VDOM) ❀ Fortinet 网络安全专家 NSE 4
- 攻略:邮件搬家同一个域名操作步骤,设置邮箱搬家功能的方法