| Author |
which is better? new a object or convert itslef
|
tony macmillan
Greenhorn
Joined: May 25, 2003
Posts: 3
|
|
package test; import java.math.BigDecimal; import java.util.HashMap; public class Mytest { public static void main(String[] args){ HashMap map = new HashMap(); BigDecimal test = new BigDecimal("100"); map.put("A",test); BigDecimal test1 = new BigDecimal(map.get("A").toString()); //1 BigDecimal test2 = (BigDecimal)map.get("A"); //2 } } } Somebody told me that the type 1 is as same as type 2, but I don�t think so. type 2 is faster than type 1 , isn's it?
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
|
Version 2 is vastly faster, yes. Parsing the string to determine a value for the new BigDecimal is a relatively expensive operation.
|
[Jess in Action][AskingGoodQuestions]
|
 |
tony macmillan
Greenhorn
Joined: May 25, 2003
Posts: 3
|
|
|
thanks a lot!
|
 |
 |
|
|
subject: which is better? new a object or convert itslef
|
|
|