首页 > 代码库 > Java数组赋值

Java数组赋值

        String [] word = {"hello", "world", "java"};
        String [] dest = new String[3];
        dest = words;
        words[0] = "nihao";
        for(String t: dest){
            System.out.println(t);
        }
        
        String [] dest2 = {"12","23","34"
        };
        System.arraycopy(words, 0, dest2, 0, 3);
        for(String t: dest2){
            System.out.println(t);

上例中,dest = words,实际上只是将dest指向了word的内容区域,因此当修改word中的内容时,dest对应的内容也会随之修改

若需要值传递的话,采用System.arraycopy(source, index1, dest, index2, length)来进行