android上运行compare,java - android compare arrays - Stack Overflow

博主在博客中分享了自己在Android开发中遇到的一个问题:一个简单的游戏应用从SQL获取订单,玩家完成订单后对比两个数组是否相同。初始化了`combo`和`order1`两个字符串数组,并在游戏过程中更新`combo`。然而,收到市场反馈称该功能在某些设备上不工作。代码使用了一个简单的逐元素比较方法检查两个数组是否相等。博主希望得到帮助,确认代码是否存在不兼容性问题或不正常情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As I am not the best in android development, I tried something that works for me and for friend's mobile, but i have some reports from market that it doesn't work for all devices maybe and do wrong compare. Anyway. the project is simple, it grabs an order from sql and in the game the player try to finish it. So I have 2 arrays. I call this at start:

final String[] combo = new String[] {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};

final String[] order1 = new String[] {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};

for(int i = 0; i < combo.length; i++) {

combo[i] = new String();

combo[i] = "0";

order1[i] = new String();

order1[i] = "0";

}

and during the game if the player clicks a button it changes the value of combo, for example, combo[7] = "1";

When he click the final button I check that 2 arrays with this

String IsSame = compareOrder(combo, order1);

and then

if (IsSame.equals("TRUE")) {

// commands

}

else if (IsSame.equals("FALSE")) {

// commands

}

private String compareOrder(String[] a, String[] b){

String n1 = "TRUE";

for (int i = 0; i < 13; i++) {

if (a[i].equals(b[i])==false) {n1 = "FALSE";}

}

return n1;

}

It looks ok for me, and it's working for my mobile, but maybe the code is not so normal and it cause wrong results in other devices. So, I need help, if you see something strange and not working in my code, tell me. Thank you!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值