• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

which is better? new a object or convert itslef  RSS feed

 
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?
 
author and iconoclast
Posts: 24203
43
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!