What is the difference between = and = in Java?

12

Reading a book about the Java language, I came across some operators that I had never seen before. They are: >> , << , >>= , <<= , >>> , <<< , >>>= and <<<= . I suppose that knowing the difference between only two of these operations being >>= and >>>= , it is possible to clarify about all the others.

What is the difference between >>= and >>>= ? In what situation can they be applied?

    
asked by anonymous 27.03.2017 / 01:53

1 answer

12

That's not OOP. These are bit operators, in case they are the composite operators of assignment, then it will pick up this variable will apply the operator and the result will be saved in the variable itself. You can say that it does the inplace operation.

The >>= shifts the bits to the right and fills 0 with the ones on the left that become "empty". The >>>= does the same but disregards the signal.

class HelloWorld {
    public static void main (String[] args) {
        int x = -100;
        x >>= 2;
        System.out.println(x);
        x = 100;
        x >>= 2;
        System.out.println(x);
        x = -100;
        x >>>= 2;
        System.out.println(x);
        x = 100;
        x >>>= 2;
        System.out.println(x);
    }
}

See running on ideone . And at Coding Ground . Also put it on GitHub for future reference .

    
27.03.2017 / 01:59