Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 17th, 2002, 01:58 AM
10_little_orcs 10_little_orcs is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Southern Germany
Posts: 9 10_little_orcs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question sort Strings

Hi,

I'm working on a part of an application where you can choose a currency from a table. The table is filled via a method called "getAllCurrencies". each row contains the abbreviation as well as the currency's name.

My problem is, the displayed 2-column table is unsorted so far.
My predecessor simply reads the abbreviations into one String array and the names into another and then
puts them together in a java.util.properties object.
getAllCurrencies then returns the properties object.

As I'm quite new to Java, I've no idea how to sort this, as I've read that the properties class itself doesn't provide a sort-method.
Should I use another class instead of properties inside the method?
It will still have to return a properties object, as I don't know if this method is called elsewhere.

Thanks in advance,

10_little_orcs

Reply With Quote
  #2  
Old October 17th, 2002, 12:46 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Where do you get the abbreviations and currencys? Database or text file? If it's in a database, you can order them in the query. This would be easier.

Reply With Quote
  #3  
Old October 18th, 2002, 01:49 AM
10_little_orcs 10_little_orcs is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Southern Germany
Posts: 9 10_little_orcs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unfortunately I get the currencies via a remote command method from a text file on a distant server, so there is no query.
And this remote command method is something I mustn't touch, because several other applications use it.

Reply With Quote
  #4  
Old October 18th, 2002, 08:54 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
EDIT: realized a problem with my reply. You have 2 arrays that must stay in sync, so the sorting method I suggested will cause problems. There is probably a way to keep them in sync, but you will have to give it some thought. Below is my original reply.

Second EDIT: It is unclear how the data is being stored in the Properties object. If you are indeed saving them as key/value pairs, then you may have to rethink your collection strategy. You may have to create your own sorted map (because map type collections like HashMap, HashTable, Properties, do not guarantee the order of the elements retrieved). Or you could use an ArrayList and store the data. Each "record" could be a 2 dimensional array of key/value and you would have to sort them before storing them, or use Collections.sort and create your own Comparable object to compare them. GL

----------------------------

First of all, seems kind of odd to use a properties object to store the data in. This is not the usual use of this collection, however it should work and I understand you are inheriting someone elses code.

One thing you can do is sort the arrays before putting them into the Properties collection. Since the String object implements the Comparable interface, it can be sorted with several premade sorting API's.

In this case I would use the Arrays Object. Arrays.sort(Object[]) will sort an array of Strings in ascending order. This is a static method so you don't have to instantiate an Arrays object to use it. Run the array through this method before putting it in the Properties collection and you should be good to go.

Last edited by Nemi : October 18th, 2002 at 09:19 AM.

Reply With Quote
  #5  
Old October 18th, 2002, 11:43 AM
10_little_orcs 10_little_orcs is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Southern Germany
Posts: 9 10_little_orcs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OK, that helps a lot - I didn't even know in which direction to turn.
I already tried to sort the arrays but, as you mentioned, the properties object mixed everything up again.
I will now try to use the ArrayList and create my own Comparable object.

Thank you very much for your help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > sort Strings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway