我是靠谱客的博主 聪明自行车,这篇文章主要介绍System.arraycopy方法使用,现在分享给大家,希望可以做个参考。

System.arraycopy方法使用

System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制。

其函数原型是:

public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
登录后复制

参数解释:

注意:src and dest都必须是同类型或者可以进行转换类型的数组.

(相关视频教程分享:java视频教程)

测试类:

public class SysTest {
 
    public static void main(String[] args) {
        String src[] = new String[] { "hello", "huang", "bao", "kang" };
        String dest[] = new String[5];
        System.arraycopy(src, 0, dest, 0, 4);
        for (String str : dest) {
            System.out.println(str);
        }
        System.out.println("=========华丽的分割线=========");
        System.arraycopy(src, 0, src, 1, 3);
        for (String str : src) {
            System.out.println(str);
        }
    }
}
登录后复制

控制台输出结果:

hello
huang
bao
kang
null
=========华丽的分割线=========
hello
hello
huang
bao
登录后复制

以上就是System.arraycopy方法使用的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是聪明自行车最近收集整理的关于System.arraycopy方法使用的全部内容,更多相关System内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(158)

评论列表共有 0 条评论

立即
投稿
返回
顶部