aspose file tools*
The moose likes Java in General and the fly likes Sorting the countries in Alphabetical Order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sorting the countries in Alphabetical Order" Watch "Sorting the countries in Alphabetical Order" New topic
Author

Sorting the countries in Alphabetical Order

sai jyothi
Greenhorn

Joined: Jun 28, 2009
Posts: 28
Hi ranchers

I am trying to sort the countries names in alphabetical order.With the code below sorting is happening but there is an issue with performance.whenever the user selects a country there is a while loop which gets executed again n again.Can we minimise this part of code ?




Thanks
Jyothi


scjp5.0 90%
consistent hardwork always gives fruitful results
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1527
sai jyothi wrote:... there is a while loop which gets executed again n again.

Where?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

I personally would have used the TreeMap instead, no overhead of sorting.
sai jyothi
Greenhorn

Joined: Jun 28, 2009
Posts: 28
There is another method where the control goes to where while loop gets execute



So the control goes to this while loop.
sinchan banerje
Greenhorn

Joined: Dec 14, 2011
Posts: 7

Hi,

From the code that you have written it is clear you need to add values to a Map if the keyLength is equal to AccountOpeningConstants.TWO_CHAR_LEN and return a sorted Map of the key value pairs.

I dont think there is a problem with your sortByComparator() method bcause it is outside the while loop . However, the code of while seems an overhead.

the code could be:
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Just a trying to clear a doubt...

Are you perhaps saying that you have a drop down or similar in your user interface and when a user traverses
the list of countries, for each country, these methods get called?
sai jyothi
Greenhorn

Joined: Jun 28, 2009
Posts: 28
Yes please.It is a combo box where countries are sorted according to alphabetical order.
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
ok lets say you have 5 countries and these countries are loaded in to the combo box.

Now when a user tries to select a country, say the one at the bottom these methods get called 5 times?

if this is the case then your user interface may be firing these methods in a way you did not expect and you may need to look at that level.

I've come across some similar issues in the past and just thought to check and if it is
not then ignore this line of thinking.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

Nitin Surana wrote:I personally would have used the TreeMap instead, no overhead of sorting.

Do you mean no visible overhead in calling a sort() method? This is correct.
But a TreeMap keeps things in sorted order. That requires overhead.
sai jyothi
Greenhorn

Joined: Jun 28, 2009
Posts: 28
Sorry guys for not giving response.Was stuck with some other issues in project.Yes it is the user interface that is firing these methods.Please let me know your apporach

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting the countries in Alphabetical Order