Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Simple way to use String.toLowerCase() for 9 kinds of languages?

Tags:

java

I need to treat 9 kinds of language in a list below.

  • Dutch
  • English
  • French
  • German
  • Italian
  • Portuguese
  • Russian
  • Spanish
  • Ukrainian

For words in these languages I need to use tolowercase(). and I know I need to use Locale(country, language) as a parameter of the function. Then, do I have to use specific locale for each language, or is there simpler way to do this?

like image 748
이승원 Avatar asked Mar 13 '13 04:03

이승원


1 Answers

You can construct a Locale from an ISO 639 language code:

Locale russian = new Locale("RU");

There are nice default locales for you to use, for example:

Locale english = Locale.ENGLISH;
Locale french = Locale.FRENCH;
Locale german = Locale.GERMAN;
Locale italian = Locale.ITALIAN;

Then just use String#toLowerCase() with the locale:

String lower = str.toLowerCase(someLocale);
like image 142
Andrew Mao Avatar answered Sep 28 '22 23:09

Andrew Mao