J
Jeff
Last Friday, I posted a question about sorting two dimensional arrays which
evoked some great responses on the exact nature of two dimensional arrays in
Java. That discussion made me refine what I was trying to accomplish and
how. Now I'd like to get other opinions on my new approach.
Here's the problem. My input is data that has 4 fields: 1 String, 1 float,
2 ints. The input comes from various other classes - it's not in rows. The
String is the subject, the float and ints describe the subject. A separate
program eventually puts my output in a 2 dimensional Swing table. Up to 1000
rows can arrive as input, but I want to pass the presenting program only the
top 15 rows. The rows with the largest float values are selected for
presentation, thus the need to sort the input.
One other influence. I typically use Vectors of Vectors to implement my
Swing table model.
The best solution I can think of is to extend Vector to implement the
Comparable interface, creating a class called ComparableVector for each row.
In ComparableVector's compareTo() method, I'll compare the float value of
each row. Then I can use the Arrays.sort() method to perform the sort. A
Vector of ComparableVectors will provide the 2nd dimension.
Does someone see a better solution?
evoked some great responses on the exact nature of two dimensional arrays in
Java. That discussion made me refine what I was trying to accomplish and
how. Now I'd like to get other opinions on my new approach.
Here's the problem. My input is data that has 4 fields: 1 String, 1 float,
2 ints. The input comes from various other classes - it's not in rows. The
String is the subject, the float and ints describe the subject. A separate
program eventually puts my output in a 2 dimensional Swing table. Up to 1000
rows can arrive as input, but I want to pass the presenting program only the
top 15 rows. The rows with the largest float values are selected for
presentation, thus the need to sort the input.
One other influence. I typically use Vectors of Vectors to implement my
Swing table model.
The best solution I can think of is to extend Vector to implement the
Comparable interface, creating a class called ComparableVector for each row.
In ComparableVector's compareTo() method, I'll compare the float value of
each row. Then I can use the Arrays.sort() method to perform the sort. A
Vector of ComparableVectors will provide the 2nd dimension.
Does someone see a better solution?