zoukankan      html  css  js  c++  java
  • 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("
    dest目标数组为:");
                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("
    复制完成之后的目标数组为:");
                for(char c : dest){
                    System.out.print(c);
                }
            }
        }

    结果输出如下:
    src源数组为:hellow
    dest目标数组为:12345789
    复制完成之后的dest目标数组为:123hell9

  • 相关阅读:
    [Android] 开源框架 xUtils HttpUtils 代理设置 (Temporary Redirect错误)
    [Android] 开源框架 Volley 自定义 Request
    [算法]——汉诺塔的递归深度
    [libwww-perl]——POST方法的使用
    [Go语言]从Docker源码学习Go——Interfaces
    [Linux]可用于管道操作的命令
    npoi 导出word中写入特殊字符
    thinkphp框架中使用PHPExcel,按模板导出excel
    Access导出csv 内容添加双引号 vba
    导出excel和PDF小结 vba
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/11438403.html
Copyright © 2011-2022 走看看