发表于: java/j2ee | 作者: | 日期: 2011/3/11 05:03

在java中数组复制有三种方法:

1、使用FOR循环,这个比较简单略过不表;

2、使用System.arraycopy(s,start1,t,start2,length)方法;

已经总结过,见如下链接:

System.arraycopy()使用小记

3。使用clone方法。

示例如下:


package com.darkmi.basic;

public class ArrayCopy {

public static void main(String[] args) {
String[] strs1 = { “aaa”, “bbb”, “ccc” };

String[] strs2 = (String[]) strs1.clone();

strs1[0] = “ddd”;

for (int i = 0; i < strs1.length; i++) { System.out.println("strs1[" + i + "] = " + strs1[i]); } for (int i = 0; i < strs2.length; i++) { System.out.println("strs2[" + i + "] = " + strs2[i]); } } }

关于clone()方法的详细介绍参考如下链接:

http://www.javaeye.com/topic/182772

http://www.javaeye.com/topic/483469

: https://blog.darkmi.com/2011/03/11/1608.html

本文相关评论 - 1条评论都没有呢
Post a comment now » 本文目前不可评论

No comments yet.

Sorry, the comment form is closed at this time.