System.arraycopy

 /*
native关键字 本地方法 System类 java.lang.System.class
参数说明:
src - 源数组。
srcPos - 源数组中的起始位置。
dest - 目标数组。
destPos - 目标数据中的起始位置。
length - 要复制的数组元素的数量。
*/
public static native void arraycopy(Object src, int srcPos,Object dest, int destPos,int length);

Arrays.copyOf();该方法对于不同的数据类型都有相应的方法重载

/*
original - 要复制的数组
newLength - 要返回的副本的长度
newType - 要返回的副本的类型
*/
//基本数据类型
public static int[] copyOf(int[] original, int newLength)
//复杂数据类型 由U类型复制为T类型
public static <T,U> T[] copyOf(U[] original, int newLength, Class<?extends T[]> newType)

Arrays.copyOfRange()方法

/*
original 要复制的数组
from初始索引
to最终索引
newType 要返回的副本类型
*/
//基本类型 可以使short、int、byte.....
public static <T> T[] copyOfRange(T[] original, int from, int to)
{
return copyOfRange(original, from, to, (Class<T[]>)original.getClass());
}
//复杂类型 由U类型转为T类型
public static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)

代码:

System.arraycopy

int a[]={0,1,2,3,4,5,6,7,8,9,11};
int ab[] = new int[5];
System.arraycopy(a, 0, ab, 0, 5);
for (int i : ab) {
System.out.println(i);
}

Arrays.copyOf 基本数据类型

int a[]={0,1,2,3};
//original a[] newLength 新数组长度 如果大于老数组长度数组元素为0
int c[] = Arrays.copyOf(a, 5);
for (int i : c) {
System.out.println(i);
}

Arrays.copyOf 复杂数据类型

// Short 数组
Short shortArr[] = new Short[]{5, 2, 15, 52, 10};
// copy Short 数组 返回 Number[]数组
Number[] arr2 = Arrays.copyOf(shortArr, 5, Number[].class);
//遍历Number[]
System.out.println("arr2 数组值:");
for (Number number : arr2) {
System.out.println("Number = " + number);
}

Arrays.copyOfRange

int a[]={0,1,2,3,4,5};
//original a[]数组 from初始索引 to最终索引
int ab[] = Arrays.copyOfRange(a, 0, 8);
for (int i : ab) {
System.out.println(i);
}

复制数组: Arrays.copy 实现通过System.arraycopy完成

System.arraycopy 和 Arrays.copyOf的更多相关文章

  1. Java-Java中System.arraycopy() 和 Arrays.copyOf()两者之间的区别

    如果我们想拷贝一个数组,我们可能会使用System.arraycopy()或者Arrays.copyof()两种方式.在这里,我们将使用一个比较简单的示例来阐述两者之间的区别. 1.示例代码: Sys ...

  2. Java中 System.arraycopy() 和 Arrays.copyOf()方法

    System.arraycopy() 和 Arrays.copyOf()方法 阅读源码的话,我们就会发现 ArrayList 中大量调用了这两个方法.比如:我们上面讲的扩容操作以及add(int in ...

  3. 论java中System.arrayCopy()与Arrays.copyOf()的区别

    如果我们想拷贝一个数组,我们可能会使用System.arraycopy()或者Arrays.copyof()两种方式.在这里,我们将使用一个比较简单的示例来阐述两者之间的区别. 首先先说System. ...

  4. System.arraycopy()和Arrays.copyOf()的区别

    先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...

  5. java数组的拷贝四种方法:for、clone、System.arraycopy、arrays.copyof

    public class ArrayCopy{ public static void main(String []args){ int []a = {1,3,4,5}; toPrint(a); int ...

  6. System.arraycopy和arrays.copyOf

    public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length); 这 ...

  7. 再谈System.arraycopy和Arrays.copyOf

    之前转载过一篇博文,介绍过这两个方法,今天想要再次详细的了解一下. public static native void arraycopy(Object src, int srcPos, Object ...

  8. JAVA System.arraycopy 和Arrays.copyof 效率比较

    System.arraycopy()源码.可以看到是native方法: native关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中. ...

  9. Arrays.copyOf() 和 System.arrayCopy()分析

    java数组的拷贝四种方法:for.clone.System.arraycopy.Arrays.copyof public class Test1 { public static void main( ...

随机推荐

  1. 机器学习: t-Stochastic Neighbor Embedding 降维算法 (一)

    Introduction 在计算机视觉及机器学习领域,数据的可视化是非常重要的一个应用,一般我们处理的数据都是成百上千维的,但是我们知道,目前我们可以感知的数据维度最多只有三维,超出三维的数据是没有办 ...

  2. Expression Design与Blend制作滚动的小球动画教程

    原文:Expression Design与Blend制作滚动的小球动画教程 一,开发工具 Microsoft Expression Design & Blend 4.0 (3.0亦可). 这两 ...

  3. uva 11346 - Probability(可能性)

    题目链接:uva 11346 - Probability 题目大意:给定x,y的范围.以及s,问说在该范围内选取一点,和x,y轴形成图形的面积大于s的概率. 解题思路:首先达到方程xy ≥ s.即y ...

  4. matlab 工具函数 —— axnote(在坐标轴上写文本内容)

    function axnote(string) font_size = get(0, 'DefaultAxesFontSize'); if 1 h1 = text(0.99, 0.05, string ...

  5. html5中 table数据导出到excel文件

    JS代码: /** * table数据导出到excel * 形参 table : tableId ; * sheetName : 工作薄名 * fileName : 文件名 * linkId :隐藏的 ...

  6. WPF里的一些Effect特效

    原文:WPF里的一些Effect特效 Blend的特效都在Microsoft.Expression.Media.Effects里,用之前添加一下引用. 可以在前台选中对象后直接点击Effect新建一种 ...

  7. angular form set dynamic control(form动态设置control)

    实现效果 form表单控件的实时更新 效果如图 关键代码 validateForm: FormGroup; // 表单校验 constructor( private fb: FormBuilder ) ...

  8. C# WebBrowser的使用

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  9. Qt中使用Boost

    编译BOOST库 bjam stage --toolset=qcc --without-graph --without-graph_parallel --without-math --without- ...

  10. Win8 Metro(C#)数字图像处理--2.45图像雾化效果算法

    原文:Win8 Metro(C#)数字图像处理--2.45图像雾化效果算法 [函数名称]   图像雾化         AtomizationProcess(WriteableBitmap src,i ...