• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

sorry array objects

Hi,

I am working on below examples

http://www.avajava.com/tutorials/lessons/how-do-i-sort-an-array-of-objects-with-a-comparator.html
http://www.avajava.com/tutorials/lessons/how-do-i-display-all-available-locales.html
I got output as

Unsorted:
ja_JP, es_PE, en, ja_JP_JP, es_PA, sr_BA, mk, es_GT, ar_AE, no_NO, sq_AL, bg, ar_IQ, ar_YE, hu, pt_PT, el_CY, ar_QA, mk_MK, sv, de_CH, en_US, fi_FI, is, cs, en_MT, sl_SI, sk_SK, it, tr_TR, zh, th, ar_SA, no, en_GB, sr_CS, lt, ro, en_NZ, no_NO_NY, lt_LT, es_NI, nl, ga_IE, fr_BE, es_ES, ar_LB, ko, fr_CA, et_EE, ar_KW, sr_RS, es_US, es_MX, ar_SD, in_ID, ru, lv, es_UY, lv_LV, iw, pt_BR, ar_SY, hr, et, es_DO, fr_CH, hi_IN, es_VE, ar_BH, en_PH, ar_TN, fi, de_AT, es, nl_NL, es_EC, zh_TW, ar_JO, be, is_IS, es_CO, es_CR, es_CL, ar_EG, en_ZA, th_TH, el_GR, it_IT, ca, hu_HU, fr, en_IE, uk_UA, pl_PL, fr_LU, nl_BE, en_IN, ca_ES, ar_MA, es_BO, en_AU, sr, zh_SG, pt, uk, es_SV, ru_RU, ko_KR, vi, ar_DZ, vi_VN, sr_ME, sq, ar_LY, ar, zh_CN, be_BY, zh_HK, ja, iw_IL, bg_BG, in, mt_MT, es_PY, sl, fr_FR, cs_CZ, it_CH, ro_RO, es_PR, en_CA, de_DE, ga, de_LU, de, es_AR, sk, ms_MY, hr_HR, en_SG, da, mt, pl, ar_OM, tr, th_TH_TH, el, ms, sv_SE, da_DK, es_HN

Sorted:
ar, ar_AE, ar_BH, ar_DZ, ar_EG, ar_IQ, ar_JO, ar_KW, ar_LB, ar_LY, ar_MA, ar_OM, ar_QA, ar_SA, ar_SD, ar_SY, ar_TN, ar_YE, be, be_BY, bg, bg_BG, ca, ca_ES, cs, cs_CZ, da, da_DK, de, de_AT, de_CH, de_DE, de_LU, el, el_CY, el_GR, en, en_AU, en_CA, en_GB, en_IE, en_IN, en_MT, en_NZ, en_PH, en_SG, en_US, en_ZA, es, es_AR, es_BO, es_CL, es_CO, es_CR, es_DO, es_EC, es_ES, es_GT, es_HN, es_MX, es_NI, es_PA, es_PE, es_PR, es_PY, es_SV, es_US, es_UY, es_VE, et, et_EE, fi, fi_FI, fr, fr_BE, fr_CA, fr_CH, fr_FR, fr_LU, ga, ga_IE, hi_IN, hr, hr_HR, hu, hu_HU, in, in_ID, is, is_IS, it, it_CH, it_IT, iw, iw_IL, ja, ja_JP, ja_JP_JP, ko, ko_KR, lt, lt_LT, lv, lv_LV, mk, mk_MK, ms, ms_MY, mt, mt_MT, nl, nl_BE, nl_NL, no, no_NO, no_NO_NY, pl, pl_PL, pt, pt_BR, pt_PT, ro, ro_RO, ru, ru_RU, sk, sk_SK, sl, sl_SI, sq, sq_AL, sr, sr_BA, sr_CS, sr_ME, sr_RS, sv, sv_SE, th, th_TH, th_TH_TH, tr, tr_TR, uk, uk_UA, vi, vi_VN, zh, zh_CN, zh_HK, zh_SG, zh_TW


my question is where from the program getting input values to sort them as above.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
gudii9
Asked:
gudii9
  • 3
  • 2
  • 2
2 Solutions
 
Ken ButtersCommented:
These are locale's.


The are read in with this line:
Locale locales[] = Locale.getAvailableLocales();

Open in new window


Review this website of supported Locales:
http://www.oracle.com/technetwork/java/javase/locales-137662.html
0
 
gudii9Author Commented:
So it prints from java runtime?
Other example
http://www.avajava.com/tutorials/lessons/how-do-i-display-all-available-locales.html


Is not resulting any webpage with locale display. My code looks as below

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() + "&nbsp;</td><td>" + locale.getCountry() + "&nbsp;</td><td>"
					+ locale.getDisplayCountry() + "&nbsp;</td><td>" + locale.getDisplayLanguage() + "&nbsp;</td><td>"
					+ locale.getDisplayName() + "&nbsp;</td><td>" + locale.getDisplayVariant() + "&nbsp;</td><td>"
					+ locale.getISO3Country() + "&nbsp;</td><td>" + locale.getISO3Language() + "&nbsp;</td><td>"
					+ locale.getLanguage() + "&nbsp;</td><td>" + locale.getVariant() + "&nbsp;</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);
	}

}

Open in new window



How to fix it. please advise
0
 
krakatoaCommented:
my question is where from the program getting input values to sort them as above

from the table :

"available-locales.htm"
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Ken ButtersCommented:
I cut and pasted your code exactly, with a new project in Eclipse.

Running the code produced this output page.

@ krakatoa... the program doesn't get the codes from available-locals.htm.... the program creates available-locales.html
available-locales.htm
0
 
gudii9Author Commented:
I cut and pasted your code exactly, with a new project in Eclipse.

Running the code produced this output page.



Run as java application right not run on server.

I did run as java application and it did not generate html page for me some reason.
0
 
Ken ButtersCommented:
I ran it as java application... I did not run on server either.

When I ran it in eclipse as java application ... the available-locals file showed up under the "JRE System Library" folder ... see  attached screenshot:
2-3-2014-1-25-49-PM.jpg
0
 
krakatoaCommented:
gudii - thanks, but you shouldn't have awarded the points to me on this occasion - I misread your quoted code on a quick scan, and missed the fact that it was generating not accessing the table. Apologies.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now