一维数组
创建数组(Create an array)
data type [] arry= new data type[length];
获取长度(Get length):
int length = arr.length;
访问具体元素(Access specific elements)
arry[Subscript];
赋值(Assignment)arry[subscript]=value; 遍历数组(Traversal array) Method of one(for method):
for(i=0;i<length;i++){
System.out.println(arry[i]);
}
创建数组并附值(Create an array and attach values.)
int[] arry = new int[]{element,element,...};
基本操作(Basic operation)
// 扩容(Expand capacity) 添加元素(Add element)
//step1: int[] newArray = new int[array.lengrh+increase];
//step2: for(int i =0 ; i<array.length;i++){
newArray[i] = array[i];
}
//step3: int a = value; newArry[array.length] = a;
//step4: arrary = newArrary;
//删除元素(Delete element):
//step1 :int[] newArray = new int[array.length-1];
int a = value;
// step2: for(int i =0 ; i<newArray.length-1;i++){
if(i<i){newArray[i] = arry[i];
}eles{
newarray[i]=arry[i+1];
}
// step3: array=newArray;
面向对象 数组(Object-oriented array) 写方法对数组进行操作(The write method operates on the array) 可变数组
Myarray ma = new Myarray();
线性查找: 从左到右一一比对(Linear search: one by one from left to right)
二分法查找: 有序数组多次一分为二,分别查找(Dichotomy search: the ordered array is divided into two for many times and searched separately)