# Java-如何快速判断一个数组是不是另一个数组的倒序？

int[] data1 = {14,-70,-18,88,85,97,-65,13,-71,-12};
int[] data2 = {-12,-71,13,-65,97,85,88,-18,-70,14};

### 评论（15）

2017-09-12 15 楼

```#define block xx
...
for(int i=0; i<len; i+=block)
...
for(int i=1; i<len; i+=block)
...
for(int i=block-1; i<len; i+=block)
...```

2017-08-07 14 楼

ps：期待大神。

2017-07-29 13 楼

boolean isArrayReverse(int[] data1, int[] data2) {

if (data1.length != data2.lenght){
return false;
}

int len = data1.length();
boolean ret = true;
for (int i=0; i<len ; ++i) {
if (data1[i] != data2[len - i - 1]) {
ret = false;
break;
}
}

return ret;
}

2017-07-26 12 楼

2017-07-11 11 楼

2017-07-01 10 楼

2017-06-17 9 楼

1、现判断长度
2、data1 data2前后对比，比较不成功就break;

2017-06-10 8 楼

issamereverse xs ys= xs == reverse ys
</coding>

2017-06-01 7 楼

public static boolean compare(int[] a, int[] b) {
if (a == null || a.length == 0 || b == null || b.length == 0) {
return false;
}
if (a.length != b.length) {
return false;
}

int l = a.length;

for (int i = 0; i < l / 2; i++) {
if (a[i] != b[l - i - 1])
return false;
}
for (int i = l / 2; i < l; i++) {
if (a[i] != b[l - i - 1])
return false;
}
return true;
}

2017-05-07 6 楼

2017-05-06 5 楼

2017-05-03 4 楼

<coding-1 lang="java">
public void test1(){
int[] data1 = {14,-70,-18,88,85,97,-65,13,-71,-12};
int[] data2 = {-12,-71,13,-65,97,85,88,-18,-70,14};
int length = data1.length;
if(length == data2.length){
int i=0;
while(i<length){
if(data1[i] == data2[length-(i+1)]){
i++;
}
}
if(i==(length)){
System.out.println("data1为data2的逆序。");
}else{
System.out.println("data1不为data2的逆序。");
}

}else{
System.out.println("data1不为data2的逆序。");
}
}

</coding>

2017-05-03 3 楼

2017-02-14 2 楼

boolean equalsReverse(int[] data1,int[] data2){
if(data1.length!=data2.length)return false;
for(int i=0;i<data1.length;i++){
if(data1[i]!=data2[data1.length-i-1])return false;
}
return true;
}

boolean equalsReverse(int[] data1,int[] data2){
List l = new ArrayList();
return l.toString().equals(Arrays.toString(data1));
}

2017-02-09 1 楼

Java代码如下：

public static boolean isArrayReverse(Object[] o1,Object[] o2) {
if(o1.length != o2.length) return false;
for(int i = 0;i<o1.length;i++){
if(!o1[i].equals(o2[o2.length - i - 1])) return false;
}
return true;
}

1904 主题
5597 回复
18932 人气