The AvailableLocales class gets an array of available locales, sorts the array by the toString() values of the locales, and then displays the values returned by several of the methods on the Locale objects. It writes the results to a file in an html table format.
AvailableLocales.java
package Pack;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
public class AvailableLocales {
public static void main(String[] args) throws Exception {
Locale locales[] = Locale.getAvailableLocales();
sortLocalesOnToString(locales);
FileWriter fw = new FileWriter("available-locales.htm");
fw.write("<table border=1 cellpadding=2 cellspacing=0>");
fw.write("<tr><th>toString</th><th>Country</th><th>" + "DisplayCountry</th><th>DisplayLanguage</th><th>"
+ "DisplayName</th><th>DisplayVariant</th><th>" + "ISO3Country</th><th>ISO3Language</th><th>"
+ "Language</th><th>Variant</th></tr>\n");
for (Locale locale : locales) {
fw.write("<tr><td>" + locale.toString() + " </td><td>" + locale.getCountry() + " </td><td>"
+ locale.getDisplayCountry() + " </td><td>" + locale.getDisplayLanguage() + " </td><td>"
+ locale.getDisplayName() + " </td><td>" + locale.getDisplayVariant() + " </td><td>"
+ locale.getISO3Country() + " </td><td>" + locale.getISO3Language() + " </td><td>"
+ locale.getLanguage() + " </td><td>" + locale.getVariant() + " </td></tr>\n");
}
fw.write("</table>");
fw.flush();
fw.close();
}
public static void sortLocalesOnToString(Locale[] locales) {
Comparator<Locale> localeComparator = new Comparator<Locale>() {
public int compare(Locale locale1, Locale locale2) {
return locale1.toString().compareTo(locale2.toString());
}
};
Arrays.sort(locales, localeComparator);
}
}
AvailableLocales.java
package Pack;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
public class AvailableLocales {
public static void main(String[] args) throws Exception {
Locale locales[] = Locale.getAvailableLocales();
sortLocalesOnToString(locales);
FileWriter fw = new FileWriter("available-locales.htm");
fw.write("<table border=1 cellpadding=2 cellspacing=0>");
fw.write("<tr><th>toString</th><th>Country</th><th>" + "DisplayCountry</th><th>DisplayLanguage</th><th>"
+ "DisplayName</th><th>DisplayVariant</th><th>" + "ISO3Country</th><th>ISO3Language</th><th>"
+ "Language</th><th>Variant</th></tr>\n");
for (Locale locale : locales) {
fw.write("<tr><td>" + locale.toString() + " </td><td>" + locale.getCountry() + " </td><td>"
+ locale.getDisplayCountry() + " </td><td>" + locale.getDisplayLanguage() + " </td><td>"
+ locale.getDisplayName() + " </td><td>" + locale.getDisplayVariant() + " </td><td>"
+ locale.getISO3Country() + " </td><td>" + locale.getISO3Language() + " </td><td>"
+ locale.getLanguage() + " </td><td>" + locale.getVariant() + " </td></tr>\n");
}
fw.write("</table>");
fw.flush();
fw.close();
}
public static void sortLocalesOnToString(Locale[] locales) {
Comparator<Locale> localeComparator = new Comparator<Locale>() {
public int compare(Locale locale1, Locale locale2) {
return locale1.toString().compareTo(locale2.toString());
}
};
Arrays.sort(locales, localeComparator);
}
}
0 comments:
Post a Comment