Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java BigDecimal vs Android BigDecimal

I've faced java.math.BigDecimal and android.icu.math.BigDecimal as I require to use BigDecimal in the project.

I've realized that the Android BigDecimal requires API level 24

What is the different between these two classes? I wonder if there is any performance optimization in Android implementation?

like image 977
Mosius Avatar asked Sep 25 '18 08:09

Mosius


2 Answers

android.icu.math.BigDecimal is part of the ICU library (International Components for Unicode). Since API 24 the Android framework exposes some of the ICU4J classes for you to use. The Android documentation on Unicode and I18N support states:

Some classes in the java and android packages have equivalents to those found in ICU4J. However, ICU4J often provides broader support for standards and languages.

Don't be confused by the above quote because ICU classes do reside in the android package. They were moved to android.icu from com.ibm.icu in order to avoid conflicts.

Regarding BigDecimal in particular: I found a discussion on the internet which concludes that BigDecimal was available in ICU before it was available in Java and is kept in the library for compatibility purposes.

Bottom line: use whatever implementation you like, but java.math.BigDecimal is less likely to be deprecated in the future.

like image 92
Markus Penguin Avatar answered Sep 29 '22 02:09

Markus Penguin


Either use java.math.BigDecimal or android.icu.math.BigDecimal, there will not be performance difference between both. Because these are basic class, Android BigDecimal was re-created with reference of Java BigDecimal.

If you ask difference between both, then

  • by purpose both are same.
  • by code they may differ, can have some less or more methods. So you should read all methods in both classes to find out difference.

https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html https://developer.android.com/reference/java/math/BigDecimal

Android re-create classes to add some feature to existing classes.

like image 24
Khemraj Sharma Avatar answered Sep 29 '22 03:09

Khemraj Sharma