Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

which is better? new a object or convert itslef

 
tony macmillan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Version 2 is vastly faster, yes. Parsing the string to determine a value for the new BigDecimal is a relatively expensive operation.
 
tony macmillan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot!
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!