Are available

String a = "first_string"; String b = "second_string"; 

and the button by pressing which should change the values ​​of two variables. Did so:

 if (!click){ b = first_string; a = second_string; click = true; } else { b = first_string; a = second_string; click = false; } 

But it seems to me the code is too bulky.

Question: Is there a short solution to this problem?

  • Your question is not related to Android - Vladyslav Matviienko

1 answer 1

You can make it shorter:

 String c = a; a = b; b = c; click = !click. 
  • Is it possible to do without a boolean? - DevOma
  • @TITAN, only you know this, because only you saw your code. No one knows if the click is used anywhere else. - Vladyslav Matviienko
  • No, if only one button is pressed ... - DevOma
  • @TITAN, be kind, stop talking in riddles if you want someone to help you. If you’re not using it anywhere else, you can delete it. In the end, you can check it yourself by running the application. - Vladyslav Matviienko
  • Sorry, but I ... Alright !!! Thanks!) - DevOma