sorting arrays

Hi,

I have 3 arrays and all 3 are related by their index i.e array1[0], array2[0] and array3[0] constitute one set; similarly array1[1], array2[1] and array3[1] constitute one set.

I need to sort array1 and find the top 3 elements then from arrays 2 and 3 I need to find the relevant elements and return the value.

eg. if the sorted array's top 3 elements are array1[12], array1[2], array1[27] then from the arrays 2 and 3 i need to find array2[12], array2[2], array2[27] and array3[12], array3[2], array3[27].

How do I do it?

[558 byte] By [itcareera] at [2007-11-26 18:53:54]
# 1

> I have 3 arrays and all 3 are related by their index

> i.e array1[0], array2[0] and array3[0] constitute one

> set; similarly array1[1], array2[1] and array3[1]

> constitute one set.

> I need to sort array1 and find the top 3 elements

> then from arrays 2 and 3 I need to find the relevant

> elements and return the value.

> eg. if the sorted array's top 3 elements are

> array1[12], array1[2], array1[27] then from the

> arrays 2 and 3 i need to find array2[12], array2[2],

> array2[27] and array3[12], array3[2], array3[27].

>

> How do I do it?

You definitely need to use the HashMap... tat s the one way to identify the values

AbiSSa at 2007-7-9 6:27:56 > top of Java-index,Java Essentials,Java Programming...
# 2

If array1[0], array2[0], and array3[0] all "represent one set", then those three data should appear in a single instance of a class that represents a set.

And then you should have a single array with instances of that set.

And then you could easily sort the array without losing track of corresponding data.

paulcwa at 2007-7-9 6:27:56 > top of Java-index,Java Essentials,Java Programming...
# 3
> You definitely need to use the HashMap... tat s the> one way to identify the valuesIs this a joke?
paulcwa at 2007-7-9 6:27:56 > top of Java-index,Java Essentials,Java Programming...
# 4
> > You definitely need to use the HashMap... tat s> the> > one way to identify the values> > > Is this a joke?HashMap can be used only for two values i.e. a key and a value..Am I right?
itcareera at 2007-7-9 6:27:56 > top of Java-index,Java Essentials,Java Programming...
# 5

A HashMap can have multiple key/value pairs, and both keys and values can be other objects, including other collections objects.

But what doesn't make sense in the earlier post, is that you don't necessarily need a Map for what you described; in fact, it doesn't seem applicable at all. Maybe the other poster was thinking about using Maps like objects in Perl and other scripting languages, with named fields. But that's a poor design in Java. Or maybe he meant something else.

paulcwa at 2007-7-9 6:27:56 > top of Java-index,Java Essentials,Java Programming...