int[] x = new int[5]; int[] y = {53, 26, 37, 94}; |
int[] x = new int[n]; |
int[] x = new int[n-1]; |
程式 | 輸出 |
public class example{ > public static void main(String[] args){ int[] x = new int[3]; x[0] = 32; x[1] = 57; x[2] = 43; for(int i=0;i<=2;i++){ x[i] += 10; System.out.println(x[i]); } } } |
42 67 53 |
int[][] x = new int[5][2]; int[][] y = {{37, 62}, {57, 94}, {45, 61}}; |
程式 | 輸出 |
public class example{ > public static void main(String[] args){ int[][] x = new int[3][2]; x[0][0] = 32; x[0][1] = 84; x[1][0] = 57; x[1][1] = 62; x[2][0] = 43; x[2][1] = 18; for(int i=0;i<=2;i++){ for(int j=0;j<=1;j++){ x[i][j] += 10; System.out.println(x[i][j]); } } } } |
42 94 67 72 53 28 |
方法 | 說明 |
<ArrayList>.add(T) | 新增元素T進入指定的ArrayList |
<ArrayList>.remove(index) | 刪除位置index的元素,其後的元素會自動補上 |
<ArrayList>.isEmpty() | (boolean)判斷是否為空ArrayList |
<ArrayList>.indexOf(T) | (int)尋找元素T的位置 |
<ArrayList>.get(index) | (class)取得位置index的元素 |
<ArrayList>.size() | (int)取得大小 |
<ArrayList>.contains(T) | (boolean)是否存在元素T |