System.arraycopy复制数组方法解释
**/*
* @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 <code>src</code>
* array could not be stored into the <code>dest</code> array
* because of a type mismatch.
* @exception NullPointerException if either <code>src</code> or
* <code>dest</code> is <code>null</code>.
*/
public static native void arraycopy(Object src, int srcPos,Object dest, int destPos,int length);**
例子:
package test.demo;
public class ArrayCopyTest {
public static void main(String[] args) {
char[] src = new String("hellow").toCharArray();
char[] dest = new String("12345789").toCharArray();
System.out.print("src源数组为:");
for(char c : src){
System.out.print(c);
}
System.out.print("\ndest目标数组为:");
for(char c : dest){
System.out.print(c);
}
/*
* 开始执行数组复制操作
* 将源数组['h','e','l','l','o','w']从数组下标0开始的4位长度的数组['h','e','l','l']
* 复制到目标数组['1','2','3','4','5','6','7','8'],从下标为3的位置开始
*/
System.arraycopy(src,0,dest,3,4);
System.out.print("\n复制完成之后的目标数组为:");
for(char c : dest){
System.out.print(c);
}
}
}
结果输出如下:
src源数组为:hellow
dest目标数组为:12345789
复制完成之后的dest目标数组为:123hell9
System.arraycopy复制数组方法解释的更多相关文章
- java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别
java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别 一.java.lang.System.arraycopy() 该方法的声明: /* ...
- 002-jdk-数据结构-工具类Collections、Arrays、System.arraycopy
常用备注 一.LIst to Array List<String> list = new ArrayList<String>(); Object[] array=list.to ...
- System.arraycopy方法解释
数组拷贝 public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int lengt ...
- java的system.arraycopy()方法
java.lang.System的静态方法arraycopy()可以实现数组的复制,讲课的老师说这个方法效率比较高,如果数组有成千上万个元素,那么用这个方法,比用for语句循环快不少.于是我试了试,发 ...
- System.arraycopy方法
数组的复制有多种方法,其中有一种就是System.arraycopy方法,传闻速度也很快. 方法完整签名: public static void arraycopy(Object src, int s ...
- Java学习之System.arraycopy()方法
java.lang.System的静态方法arraycopy()可以实现数组的复制,讲课的老师说这个方法效率比较高,如果数组有成千上万个元素,那么用这个方法,比用for语句循环快不少.System提供 ...
- 复制数组之System.arraycopy()的使用
System.arraycopy(src, srcPos, dest, destPos, length); [参数说明](注:arraycopy是一个古老的方法,从jdk1.0就有了,而当时命名并不规 ...
- jdk提供的数组扩容方法:System.arraycopy
package chapter7; /* * jdk提供的扩容方法 * System.arraycopy */public class TestArrayjdk { public static voi ...
- Java中 System.arraycopy() 和 Arrays.copyOf()方法
System.arraycopy() 和 Arrays.copyOf()方法 阅读源码的话,我们就会发现 ArrayList 中大量调用了这两个方法.比如:我们上面讲的扩容操作以及add(int in ...
随机推荐
- Spring MVC源码分析(一):ContextLoaderListener的设计与实现
ContextLoaderListener在我的Spring源码分析(一):从哪里开始看spring源码这篇文章,分析过在web容器,如tomcat,启动web应用时,会通过监听器的方式,通知Serv ...
- Python面试题之阅读下面的代码,写出A0,A1至An的最终值
A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) A1 = range(10) A2 = [i for i in A1 if i in A0] A3 ...
- js 正则替换的使用方法
function compress(source) { const keys = {}; ⇽--- 存储目标key source.replace( /([^=&]+)=([^&]*)/ ...
- 编写Storm程序
- tomcat之redis
Nginx服务器:[root@nginx ~]# vim /usr/local/nginx/conf/nginx.confupstream tomcat_pool { server 192.168.2 ...
- spark运行任务报错:Container [...] is running beyond physical memory limits. Current usage: 3.0 GB of 3 GB physical memory used; 5.0 GB of 6.3 GB virtual memory used. Killing container.
spark版本:1.6.0 scala版本:2.10 报错日志: Application application_1562341921664_2123 failed 2 times due to AM ...
- Dao层结合Service层处理异常
1. 接口存在异常不利于解耦. 2. 将编译时异常转化为运行时异常或其子类,通知上层,上层可以根据自身能力选择处理或向上抛出. 举例: 将UserDao中的SQLException转化为DaoExce ...
- 【转】Git 修改已提交的commit注释
https://www.jianshu.com/p/098d85a58bf1 [重点] 通过git rebase -i HEAD~2 你想修改哪条注释 就把哪条注释前面的pick换成edit git ...
- 判断访问浏览器客户端类型(pc,mac,ipad,iphone,android)
<script type="text/javascript"> //平台.设备和操作系统 var system = { win: false, mac: false, ...
- java之短路与&&和短路或||
短路的意思就是惰性计算,符号右边的就不进行计算了. ||和&&就是这样,