1. 数组的初始化必须定义长度。
3. 遍历数组可以使用两种方式:
4. Arrays类的使用
5. 与copyOf类似的函数
6.数组转化为List
2. 数组的长度
int length = array.Length;
3. 遍历数组可以使用两种方式:
for(int i=0; i<array.Length; i++){}
for(int a : array){}
4. Arrays类的使用
int binarySearch(int[] a,int key)
使用二分查找方法,不包含返回负数,要求数组已经升序。
int binarySearch(int[] a.int from,int to,int key)
与上面要求一样
type[] copyOf(type[] original,int length)
长度以length为准,小于原始长度,则只是前length的内容,大于原始长度,不默认值。
type[] copyOfRange(type[] original, int from, int to)
与上类似
boolean equals(type[] a,type[] b)
void fill(type[] a,type val)
全部填充
void fill(type[] a,int from,int to)
与上类似
void sort(type[] a)
升序排列
void sort(type[] a,int from,int to)
与上类似
String toString(type[] a)
返回按逗号分隔的String
5. 与copyOf类似的函数
System.arraycopy(type[] src,int srcpos,type[] dest,int destpos,int length)
6.数组转化为List
List<type> Arrays.asList(type[] a),
a必须是引用类型的数组