标签:lis dex 填充 sys utils library range data asList
创建数组并声明
dataType[] arrayRefVar = new dataType[arraySize];
数组作为函数的参数
public class parent{
public void name(int[] array) {
for(int x:array) {
System.out.print(x);
}
}
public static void main(String args[]) {
int[] array = new int[3];
array[0]=1;
array[1]=2;
array[2]=3;
parent aaParent = new parent();
aaParent.name(array);
}
多维数组
String str[][] = new String[3][4];
type[][] typeName = new type[typeLength1][typeLength2];
数组方法
1、fill方法:填充数组
Arrays.fill(array, 1,3,9);
//fill(start,end,number)
2、sort方法:排序
Arrays.sort(array,2,5); //2到5排序
3、copyof()©OfRange:复制数组
int [] array=new int[]{3,7,8,2,1,9};
array2=Arrays.copyOf(array,3); //新数组的长度为3
array3=Arrays.copyOfRange(array,3,5); //复制第三到五个元素
4、contains():是否包含某个值,需要先转换为list
String[] array= new String[] {"1","2","3","4","5"};
boolean b =Arrays.asList(array).contains("2");
System.out.println(Arrays.binarySearch(array, "2"));
5、addALL():连接俩个数组
int[] intArray = { 1, 2, 3, 4, 5 };
int[] intArray2 = { 6, 7, 8, 9, 10 };
// Apache Commons Lang library
int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2);
6、定位元素位置
Arrays.binarySearch(str);//有序数组
System.out.println(Arrays.binarySearch(array, "2"));
Arrays.asList.indexOf(str);
7、将数组变成字符串
String j = StringUtils.join(new String[] { "a", "b", "c" }, ", ");
System.out.println(j);
8、数组反转
int[] intArray = { 1, 2, 3, 4, 5 };
ArrayUtils.reverse(intArray);
System.out.println(Arrays.toString(intArray));
标签:lis dex 填充 sys utils library range data asList
原文地址:https://www.cnblogs.com/Mr-l/p/11877138.html