android compare arrays(android比较数组)
问题描述
由于我在 android 开发方面不是最好的,所以我尝试了一些对我和朋友的手机有用的东西,但我有一些来自市场的报告说它可能不适用于所有设备并且做错比较.反正.该项目很简单,它从 sql 中获取一个订单,然后在游戏中玩家尝试完成它.所以我有2个数组.我一开始就这样称呼:
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";
}
在游戏过程中,如果玩家点击一个按钮,它会改变combo的值,例如combo[7] = "1";
and during the game if the player clicks a button it changes the value of combo, for example, combo[7] = "1";
当他点击最后一个按钮时,我用这个检查了 2 个数组
When he click the final button I check that 2 arrays with this
String IsSame = compareOrder(combo, order1);
然后
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!
推荐答案
不要写已经提供的东西.:-)
Don't write what is provided already. :-)
import java.util.Arrays;
TextView tv = (TextView) findViewById(R.id.text_view);
tv.setText(Arrays.equals(order1, combo)? "Equal" : "Unequal");
这篇关于android比较数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android比较数组


- 未找到/usr/local/lib 中的库 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 转换 ldap 日期 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01