?
Solved

sorry array objects

Posted on 2014-02-03
7
Medium Priority
?
374 Views
Last Modified: 2014-02-03
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
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39830264
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
 
LVL 7

Author Comment

by:gudii9
ID: 39830275
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
 
LVL 16

Assisted Solution

by:krakatoa
krakatoa earned 400 total points
ID: 39830289
my question is where from the program getting input values to sort them as above

from the table :

"available-locales.htm"
0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 19

Expert Comment

by:Ken Butters
ID: 39830307
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
 
LVL 7

Author Comment

by:gudii9
ID: 39830347
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
 
LVL 19

Accepted Solution

by:
Ken Butters earned 1600 total points
ID: 39830452
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
 
LVL 16

Expert Comment

by:krakatoa
ID: 39830967
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question