The method of array flipping (Java implementation), so-called array flipping, is to invert the array, for example the original array is: {"A", "B", "C", "D"}, then the inverted array is {"D", "C", "B", "a"}. The following implementation method, here for the sake of simplicity I borrowed the list's Add method.
Package Org.webdriver.autotest.study;import Java.util.arraylist;public class Array_examp1 {public static void main ( String[] args) { //TODO auto-generated method stub //array rollover. For example: {' A ', ' B ', ' C ', ' d '} becomes {' d ', ' C ', ' B ', ' A '} string[] array_old={"A", "B", "C", "D"}; Arraylist<string> array_new_list=new arraylist<string> (); String[] Array_new=new string[array_old.length]; for (int i=1;i<=array_old.length;i++) { array_new_list.add (array_old[array_old.length-i]); } Array_new=array_new_list.toarray (array_new); for (int j=0;j<array_new.length;j++) { System.out.print (""); System.out.print (Array_new[j]);}}
Operation Result:
D C B A
Without the use of the list, in fact, not the use of the method of the list, but also very simple, the principle of array inversion is the inverted new array, the first element is equal to the last element of the source array:
Package Org.webdriver.autotest.study;//import Java.util.arraylist;public class Array_examp1 { //array Inverted public static void Main (string[] args) { //TODO auto-generated method stub //array rollover. For example: {' A ', ' B ', ' C ', ' d '} becomes {' d ', ' C ', ' B ', ' A '} string[] array_old={"A", "B", "C", "D"}; Arraylist<string> array_new_list=new arraylist<string> (); String[] Array_new=new string[array_old.length]; for (int i=1;i<=array_old.length;i++) { //array_new_list.add (array_old[array_old.length-i]); The first element of the new array element equals the last element of the old element Array_new[i-1]=array_old[array_old.length-i]; Array_new=array_new_list.toarray (array_new); for (int j=0;j<array_old.length;j++) { System.out.print (""); System.out.print (Array_new[j]);}}
Method of array flipping (Java implementation)