1 ImportJava.util.*;2 classarray index {3 Public Static voidMain (String args[]) {4 //tools for use in arrays: Arrays5 int[] arr = {1,2,3,4};6 //finds if there is a number in the array7 intnum = 3;8 //If you have one, print the corresponding index9 intresult =Arrays.binarysearch (arr,num);TenSystem.out.println ("the corresponding index value is as follows:"); One System.out.println (result); A -System.out.println ("Ascending order is as follows:"); - int[] arr1 = {6,4,5,2}; the Arrays.sort (arr1); - for(inti:arr1) - System.out.println (i); - +System.out.println ("Sort the array in reverse order as follows:"); -Arraylist<integer> list2=NewArraylist<integer>(); + for(inti=1;i<=5;i++){ A List2.add (i); at } - Collections.reverse (list2); - //list2.size (); Indicates the length of the array - for(inti:list2) - System.out.println (i); - } in}
Common functions for Java arrays