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 ...
随机推荐
- es概念一句话简介和注意点
1.elasticsearch是什么? 一个实时分布式搜索(全文or结构化)和分析引擎,面向文档(document oriented) 2.主节点(Master Node)职责? 负责集群中的操作(如 ...
- Spring Boot整合Thymeleaf模板引擎
什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...
- 深入理解JAVA虚拟机原理之垃圾回收器机制(一)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 对于程序计数器.虚拟机栈.本地方法栈这三个部分而言,其生命周期与相关线程有关,随 ...
- 第三记 Java面向对象
相信很多人都有听到,见到这么一句话:Java是一门面向对象编程的语言,但是又是否对这句话有了自己的理解呢? 一.面向对象 面向对象是一种新兴的程序设计方法,也可以说是一种新的程序设计规范(paradi ...
- 4-Ubuntu-启动/关闭/重启mysql服务
启动: sudo service mysql start 关闭: sudo service mysql stop 重启: sudo service mysql restart
- 2018-8-10-win10-uwp-气泡
title author date CreateTime categories win10 uwp 气泡 lindexi 2018-08-10 19:16:50 +0800 2018-2-13 17: ...
- Linux(二)高级文本处理
一.cut (cut 命令可以从一个文本文件或者文本流中提取文本列 ) 1.cut语法 cut -d '分隔字符' -f fields 用于有特定分隔字符 cut -c 字符区间 ...
- 任意两点间的最短路问题(Floyd-Warshall算法)
/* 任意两点间的最短路问题(Floyd-Warshall算法) */ import java.util.Scanner; public class Main { //图的顶点数,总边数 static ...
- delphi 判断两个时间差是否在一个指定范围内
WithinPastYears.WithinPastMonths.WithinPastWeeks.WithinPastDays ... 判断两个时间差是否在一个指定范围内DateUtils.Withi ...
- curl 命令帮助及使用
目录 一.简介 二.curl 帮助文档 三.curl 的使用 前言 刚接触 curl 就发现它的非常强大.奈何帮助文档全是英文,看起来贼费劲.无奈只能硬着头皮用自己蹩脚的英语和翻译软件硬生生的翻译了一 ...