Zasito
Zasito

Reputation: 279

Modifying bigInteger after dividing Java

I've looked a lot through here and can't quite find why this line is wrong:

ArrayList <BigInteger> data = new ArrayList();
int [] primes = new int[25];    
...
// Some initializing
...
data.get(i) = data.get(i).divide( BigInteger.valueOf( primes[place] ) ); //<----
...
// Rest of the code

Required: variable; Found: value.. What I'm doing wrong?

Upvotes: 3

Views: 69

Answers (2)

Elliott Frisch
Elliott Frisch

Reputation: 201447

First, you should fix your Raw Type (and I'd prefer the List interface) like

List<BigInteger> data = new ArrayList<>();

then you need to use set because you can't assign to the return value of a get like that.

data.set(i, data.get(i).divide(BigInteger.valueOf(primes[place])));

Also, it's worth noting that BigInteger(s) are (per the Javadoc) immutable arbitrary-precision integers.

Upvotes: 6

= only works to assign variables, fields and array elements.

You probably want to call set.

data.set(i, data.get(i).divide(...etc...));

Upvotes: 5

Related Questions