我有問題。在我的主類,我有:Java - 參考變量
int ints[] = Type.desc(1000);
int auxi[] = new int [1000];
auxi = ints;
System.out.println("========== Init =========");
// Insertion Sort
Algoritmos.insertionSort(ints);
ints = auxi;
的說明方法是:
public static int[] desc (int n){
int aux[];
aux = new int[n];
int pos = 0;
for (int i = n-1; i > 0; i--) {
aux[pos++] = i;
}
return aux;
}
的整數和AUXI的值被改變。
如何保存矢量整數的初始值?
這是唯一的方法嗎? –
@RenatoShumi不是,不,也可以使用'clone()'並將其轉換爲'int []'或Arrays.copyOf()。 – dasblinkenlight
只要你不使用更高級的數據結構,比如'ArrayList' ......是的......(除了EJP提到的,即自己循環或者copyOf(),我的意思是)。 –