Array数组

Arrays.copyOf()用来实现数组的复制,返回一个数组,第一个参数是被复制的数组,第二个是复制的长度;

import java.util.Arrays;
public class  Arraydemo{
       public static void main(String[] args){
          //数组的初始化;
        String[]  students=new String[]{"liming","jack","bob"};
         String[]  teachers={"happy","will","good"};
         //遍历数组
           System.out.println("--------students----------------");
           for(int i=0;i<students.length;i++){
               System.out.println(students[i]);
           }
           System.out.println("-----------teachers-------------");
             for(int i=0;i<teachers.length;i++){
               System.out.println(teachers[i]);
           }
           //数组的拷贝
            System.out.println("----------person--------------");
           String[] person=students;
              for(int i=0;i<person.length;i++){
               System.out.println(person[i]);
           }

            System.out.println("----------copyperson--------------");

              String[]   bigPerson=Arrays.copyOf(students,2*students.length);
              for(int i=0;i<bigPerson.length;i++){
               System.out.println(bigPerson[i]);
           }




       }






}

运行结果:
——–students—————-
liming
jack
bob
———–teachers————-
happy
will
good
———-person————–
liming
jack
bob
———-copyperson————–
liming
jack
bob
null
null
null

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值