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比较数组


基础教程推荐
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01