Android Comparison Arrays

Hi guys, since I'm not the best in Android development, I tried something that works for me and for a mobile friend, but I have some reports that from a market that it cannot work on all devices, maybe wrong. In any case, the project is simple, it captures the order from sql, and in the game the player tries to complete it. So I have 2 arrays. I will name it at the beginning:

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 pressed the button, he changed the value of the combo, for example combo [7] = "1";

When he presses the last button, I check that there are 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; } 

This looks good to me, and it works on my mobile phone, but maybe the code is not so normal, and this leads to incorrect results on other devices. So I need help, if you see something strange and not working in my code, tell me. Thanks!

+4
source share
1 answer

Do not write what is already provided. :-)

 import java.util.Arrays; TextView tv = (TextView) findViewById(R.id.text_view); tv.setText(Arrays.equals(order1, combo)? "Equal" : "Unequal"); 
+13
source

Source: https://habr.com/ru/post/1401485/


All Articles