Explicitly multiplying values as longs

Posted by Bill Szerdy on Stack Overflow See other posts from Stack Overflow or by Bill Szerdy
Published on 2010-04-03T19:37:13Z Indexed on 2010/04/03 19:43 UTC
Read the original article Hit count: 256

Filed under:
|

I understand that all math is done as the largest data type required to handle the current values but when you transverse a loop how do you explicitly multiply longs? The following code returns 0, I suspect, because of an overflow.

long result = 0L;
List<Long> temp = (List<Long>) getListOfIntegers();
for (int i = 0; i < temp.size(); i++) {
   result *= temp.get(i).longValue();
}
System.out.println(result);

© Stack Overflow or respective owner

Related posts about java

Related posts about math