数组的反转
方式一:
String[] reverse = new String[]{"AA", "BB", "CC", "DD", "EE", "FF", "GG"};
for (int i = 0; i <= (reverse.length - 1) / 2; i++) {
String tmp = reverse[i];
reverse[i] = reverse[reverse.length - i - 1];
reverse[reverse.length - i - 1] = tmp;
}
方式二:
String[] reverse = new String[]{"AA", "BB", "CC", "DD", "EE", "FF", "GG"};
for (int i = 0, j = reverse.length - 1; i < j; i++, j--) {
String tmp = reverse[i];
reverse[i] = reverse[j];
reverse[j] = tmp;
}
网友评论