Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

My Locale  RSS feed

 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HELLO

I couldn't figure out this.I'm wondering what does it mean ? I were expecting default locale of my system but there is nothing.
Now what do i with that object? what is the use of that object, could you elaborate about it?


---------- Run ----------


Output completed (0 sec consumed) - Normal Termination
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
 
Vijay Tyagi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In setRegion() , If region is null or the empty string, the region in the Builder returned is removed.
Same for setLanguage()

http://docs.oracle.com/javase/7/docs/api/java/util/Locale.Builder.html#setRegion%28java.lang.String%29
 
Tony Docherty
Bartender
Posts: 3268
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldn't figure out this.I'm wondering what does it mean ?

You have created a Locale with no region or language. This is the same as the Locale.ROOT locale.

I were expecting default locale of my system but there is nothing.

You need to do as Saifuddin Merchant has suggested.

Now what do i with that object?

That's entirely up to you.

what is the use of that object

See this thread http://www.coderanch.com/t/594833/java/java/ROOT-locale
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
I couldn't figure out this.I'm wondering what does it mean ?

You have created a Locale with no region or language. This is the same as the Locale.ROOT locale.

I were expecting default locale of my system but there is nothing.

You need to do as Saifuddin Merchant has suggested.

Now what do i with that object?

That's entirely up to you.

what is the use of that object

See this thread http://www.coderanch.com/t/594833/java/java/ROOT-locale


Can you show me API, which says it is ROOT LOCALE ? Would you elaborate it ?
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the thread I linked you to?
As for the API docs do a google for something like "Java Locale api docs 1.6"
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't find any evidence which says below statement creates a ROOT Locale object i.e. Locale.ROOT

Locale defaultLocale=new Locale.Builder().setRegion(null).setLanguage("").build();
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ankita modi. wrote:I didn't find any evidence which says below statement creates a ROOT Locale object i.e. Locale.ROOT

Me neither, but I did find:
"Builders can be reused; clear() resets all fields to their default values."
and a little look at the specific methods expands on that.

And if you're not prepared to take Tony's word for it (and he seems a fairly knowledgeable chap), then TEST IT.

Winston
 
Tony Docherty
Bartender
Posts: 3268
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies, I thought I'd copied an extract of the docs into the thread.

The docs for Locale.ROOT say "The root locale is the locale whose language, country, and variant are empty ("") strings."
And for Locale.Builder.setLanguage() and setRegion() they they say "Sets the language. If language is the empty string or null, the language in this Builder is removed." and "Sets the region. If region is null or the empty string, the region in this Builder is removed" respectively.

So Locale defaultLocale=new Locale.Builder().setRegion(null).setLanguage("").build(); creates a Locale without a region or language which is in essence the Locale.ROOT object.
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!