提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在方法内部修改数组参数
import java.util.Arrays; public class Main {//来 自 n o w j a v a . c o m - 时 代 Java public static void main(String[] args) { int[] origNum = {1, 2, 3}; System.out.println("Before method call:" + Arrays.toString(origNum)); // Pass the array to the method tryArrayChange(origNum); System.out.println("After method call:" + Arrays.toString(origNum)); } /** from 时代Java公众号 - nowjava.com**/ public static void tryArrayChange(int[] num) { System.out.println("Inside method-1:" + Arrays.toString(num)); // Create and store a new int array in num