android比较数组

2022-01-25 00:00:00 arrays compare android java

由于我在 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");

相关文章