GeeCON Prague 2014*
The moose likes Java in General and the fly likes which is better? new a object or convert itslef Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "which is better? new a object or convert itslef" Watch "which is better? new a object or convert itslef" New topic
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: 24187
    
  34

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which is better? new a object or convert itslef