4

Yes,I am new to java and this question is asked in some other links in stackoverflow ( Java equivalent of Invariant Culture). But still there is no conclusion stating that,

  1. There is no equivalent in java to do this
  2. There is an alternative

Also what will the below statement do in java.

Locale invariant = new Locale("","","");

Am interested in the above statement because in C# the below code will bring the Invariant culture setting.

CultureInfo Invc = New CultureInfo("");

I like to know whether this is possible to have invariant culture setting in java, Is it possible by any workarounds or how to write code in Java with independent culture settings. The below MSDN quote states the necessary of independent culture settings.

Storing data in a culture-independent format guarantees a known format that does not change. When users from different cultures access the data, it can be formatted appropriately based on specific user. For example, if your application stores DateTime types in a text file, formatted for the invariant culture, the application should use the InvariantCulture property when calling ToString to store the strings and the Parse method to retrieve the strings. This technique ensures that the underlying values of the DateTime types do not change when the data is read or written by users from different cultures.

Community
  • 1
  • 1
IMK
  • 654
  • 9
  • 15
  • A locale covers a lot of the same functionality as CultureInfo in C#. There is no 'invariant' version of it though as far as I know. The data is stored in a default format (time for instance in miliseconds since 1970, or stored in a fixed-culture/locale form like YYYY-mm-dd hh:mm:ss parsed in when read and written out using the specific locale). I suspect the 'invariant' culture of c# secretly writes it out as locale US_en so you could use that locale if you wish. – Joeblade Apr 21 '15 at 08:11
  • As far I knew there is some difference between "en-US" culture and Invariant culture in C#. The code `double value = 12345.6789;` `Console.WriteLine(value.ToString("C", CultureInfo.CreateSpecificCulture("en-US")));` `Console.WriteLine(value.ToString("C", CultureInfo.InvariantCulture));` produces different results – IMK Apr 21 '15 at 08:53

1 Answers1

3

Compare Locale.ROOT:

The root locale is the locale whose language, country, and variant are empty ("") strings. This is regarded as the base locale of all locales, and is used as the language/country neutral locale for the locale sensitive operations.

Av Pinzur
  • 2,188
  • 14
  • 14