By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

Sorting strings problem

P: n/a
xyz
I am trying to sort a string array. I am trying to use a collator
class, but I get errors. Do I need to an "import" statement or
something?

I would appreciate your suggestions.

/javadev/com/azdictpkg/PhraseList.java:60: cannot resolve symbol
symbol : class Collator
location: class com.azdictpkg.PhraseList
Collator c = Collator.getInstance();
^
/javadev/com/azdictpkg/PhraseList.java:60: cannot resolve symbol
symbol : variable Collator
location: class com.azdictpkg.PhraseList
Collator c = Collator.getInstance();
^
2 errors

=========================

// sort PhraseList by descending frequency,
// alphabetically ascending phrase
public void sortlist() {
int i, j, k, ftmp, icmp;
String tmp;

Collator c = Collator.getInstance(); // <<<<<<==== problem

for (i=0; i<PhraseCt-1; i++) {
k = i;
for (j=i+1; j< PhraseCt; j++) {
if (PhrD[k].PhraseFreq < PhrD[j].PhraseFreq) {
k = j;
}
else {
if (PhrD[k].PhraseFreq == PhrD[j].PhraseFreq) {
if (c.compare(PhrD[k].Phrase, PhrD[j].Phrase) > 0) {
k = j;
}
}
}
}
if (k > i) { /* exchange */
ftmp = PhrD[k].PhraseFreq;
tmp = PhrD[k].Phrase;
PhrD[k].PhraseFreq = PhrD[i].PhraseFreq;
PhrD[k].Phrase = PhrD[i].Phrase;
PhrD[i].PhraseFreq = ftmp;
PhrD[i].Phrase = tmp;
}
}
} /* sortlist() */
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
xyz
On Tue, 18 May 2004 05:04:31 GMT, xyz <xy*@mailinator.com> wrote:
I am trying to sort a string array. I am trying to use a collator
class, but I get errors. Do I need to an "import" statement or
something?
The following import is needed to use Collator:

import java.text.*;

/javadev/com/azdictpkg/PhraseList.java:60: cannot resolve symbol
symbol : class Collator
location: class com.azdictpkg.PhraseList
Collator c = Collator.getInstance();
^
/javadev/com/azdictpkg/PhraseList.java:60: cannot resolve symbol
symbol : variable Collator
location: class com.azdictpkg.PhraseList
Collator c = Collator.getInstance();
^
2 errors


Jul 17 '05 #2

P: n/a
use the static sort method of the Arrays class
Arrays.sort(yourArrayName);
"xyz" <xy*@mailinator.com> wrote in message
news:hs********************************@4ax.com...
I am trying to sort a string array. I am trying to use a collator
class, but I get errors. Do I need to an "import" statement or
something?

I would appreciate your suggestions.

/javadev/com/azdictpkg/PhraseList.java:60: cannot resolve symbol
symbol : class Collator
location: class com.azdictpkg.PhraseList
Collator c = Collator.getInstance();
^
/javadev/com/azdictpkg/PhraseList.java:60: cannot resolve symbol
symbol : variable Collator
location: class com.azdictpkg.PhraseList
Collator c = Collator.getInstance();
^
2 errors

=========================

// sort PhraseList by descending frequency,
// alphabetically ascending phrase
public void sortlist() {
int i, j, k, ftmp, icmp;
String tmp;

Collator c = Collator.getInstance(); // <<<<<<==== problem

for (i=0; i<PhraseCt-1; i++) {
k = i;
for (j=i+1; j< PhraseCt; j++) {
if (PhrD[k].PhraseFreq < PhrD[j].PhraseFreq) {
k = j;
}
else {
if (PhrD[k].PhraseFreq == PhrD[j].PhraseFreq) {
if (c.compare(PhrD[k].Phrase, PhrD[j].Phrase) > 0) {
k = j;
}
}
}
}
if (k > i) { /* exchange */
ftmp = PhrD[k].PhraseFreq;
tmp = PhrD[k].Phrase;
PhrD[k].PhraseFreq = PhrD[i].PhraseFreq;
PhrD[k].Phrase = PhrD[i].Phrase;
PhrD[i].PhraseFreq = ftmp;
PhrD[i].Phrase = tmp;
}
}
} /* sortlist() */

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 5/22/2004
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.