Why does Android Lint warn about String.format using default locale when explicitly using Locale.US? Why does Android Lint warn about String.format using default locale when explicitly using Locale.US? android android

Why does Android Lint warn about String.format using default locale when explicitly using Locale.US?


Cleaning and rebuilding the project should work.

BTW, you may want to use Locale.getDefault() to "take care" of texts not written in english.


when I mentioned the locale with the format, the lint warning just vanished.

String.format(Locale.US,"%02d", selectedInt);


Implied default locale in case conversion

Calling String#toLowerCase() or #toUpperCase() without specifying an explicit locale is a common source of bugs. The reason for that is that those methods will use the current locale on the user's device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for i is not I.

If you want the methods to just perform ASCII replacement, for example to convert an enum name, call String#toUpperCase(Locale.US) instead. If you really want to use the current locale, call String#toUpperCase(Locale.getDefault()) instead.

http://developer.android.com/reference/java/util/Locale.html#default_locale