user11129457
user11129457

Reputation:

Just like post increment do we have a post assignment in java?

I wish to change(assign) the value of an element at an index in an array:

a=array[index];
array[index]=0;

Can this be done in one line, like a post/pre increment?

Upvotes: 1

Views: 147

Answers (2)

Semjerome
Semjerome

Reputation: 43

Based from your question, you want to assign the value from the array and put it on a different variable. and then you want to assign something into it in just one line of code.

//I'm assuming that both array and variable a is initialized
array[index] = a + -array[index] + (a = array[index]); 

Upvotes: 1

Kars
Kars

Reputation: 917

Yes you can do this by calling this

int[] array = {0,0,0};

Upvotes: 1

Related Questions