String array: 'The value changed to' i ++ 'is never used'

Here is my code:

String[] queries = new String[2];
int i = 0;
Boolean result;
queries[i++] = "<query 1>";
queries[i++] = "<query 2>"; //Warning shown here
result = dbOpenHelper.ExecuteMyTransaction(queries);

The second character is i++highlighted and the warning "The value changed in" I ++ is never used "is displayed. This code was written by a different person, and as far as I know, here <query 1>and <query 2>receive, respectively, queries[1]and queries[2], then he should show an error because the array has a size of 2. There is no mistake, and it confuses me, what is happening here. Is it safe to delete the second destination or change the first to queries[i]?

+4
source share
5 answers

, i++ i.

, , i, .

+8

i ++ , , , .

, ,

String[] queries = new String[2];
int i = 0;
Boolean result;
queries[i++] = "<query 1>";
queries[i] = "<query 2>"; //change this here
result = dbOpenHelper.ExecuteMyTransaction(queries);
+6

i++ i, i . - i++ i, i.

+4
  • , 2.

queries[2], java.lang.ArrayIndexOutOfBoundsException ?. .

  • , , .

, , . ArrayIndexOutOfBoundsException ?

  • []?

, , post increment

queries[i++] = "<query 1>"; // index accessed is 0 here
queries[i] = "<query 2>"; // i=1 here
  • , 'i ++',

, , i , .

+4

++ i, . ()

i ++ , . (Post-increment)

, post post increment.

queries[i++] = "<query 1>"; // It equivalent to queries[0] = "<query 1>";
queries[i++] = "<query 2>"; // It equivalent to queries[1] = "<query 2>";

, , . , , queries[i] = "<query 2>";

+1
source

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


All Articles