public class MyTest {
public static void main(String[] args) {
String[] text = {"你","好","你","吃","了","吗","?"};
System.out.println(Arrays.toString(text));
reverse(text);
System.out.println(Arrays.toString(text));
}
public static <T> void reverse(T[] array){
int length = array.length;
for (int i=0, mid=length>>1, j=length-1; i<mid; i++, j--){
swap(array, i, j);
}
}
public static <T> void swap(T[] array,int i,int j){
T temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-47288.html