JAVA数组操作的方法

数组元素类型 数组名字[];
数组元素类型[] 数组名字;
数组名字 = new 数组元素类型[数组元素的个数];
数组元素类型 数组名 = new 数组元素的类型[数组元素的个数];
int arr[] = new int[]{1,2,3,4,5}; int arr[] = {1,2,3,4,5};
数组元素的类型 数组名字[][];
数组元素的类型[][] 数组名字;
a = new int[2][4];
a = new int[2][]; a[0] = new int[2]; a[1] = new int [3];
type arrayname[][] = {val1,val2,……};

java.util包的Arrays类包含了用来操作数组的各种方法。

## 填充替换数组元素

fill(int[] a, int value)
fill(int[] a, int fromIndex, int toIndex, int value)
对数组进行排序
sort()
复制数组
copyOf()方法是复制数组至指定的长度;
copyOfRange()方法则将指定数组的指定长度复制到一个新的数组中。
数组查询
binarySeach(Object[], Object key);
binarySeach(Object[],int fromIndex, int toIndex, Object key);

猜你喜欢

转载自blog.csdn.net/weixin_43794314/article/details/84577101