Solved

sorry array objects

Posted on 2014-02-03
7
363 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
  • 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 100 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 400 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now