my java is rusty and I was wondering if someone could give me a code sample of how to do the following:
I have a result set from a database call that returns the following table:
object_id(int), marker_id(int), xpos(float), ypos(float)
the results are grouped by object_id such that you have something like this:
1023, 19, 0.2, 0.8
1023, 63, 0.2, 0.9
1023, 63, 0.2, 0.9
1072, 63, 0.2, 0.23
1072, 63, 0.2, 0.9
1072, 63, 0.2, 0.6
1012, 63, 0.2, 0.6
1012, 63, 0.2, 0.6
I was looking for the most effective way of generating two 2d double arrays such that
the first has
double[][] array1 = {
{0.2,0.8,0.2,0.9...},
{0.2,0.8,0.2,0.9...},
...}
each sub array contains the sequence x1,y1,x2,y2,x3,y3 for row1,row2,etc… for the corresponding object_id in the result set.
The second 2d array would contain:
double[][] array2 = {
{1.0},
{0.9},
{0.8},
...
{0.0}}
Where there’s an entry for each unique object_id and the first entry has 1.0 and the last entry has 0.0
The two arrays should have the same length since each entry represents an object_id
Hope that makes sense
Thanks
Edited Answer Below
“I need to transform it into arrays for input to another library. – user257543”
Well in order to do that, one approach is to turn the columns into an array and then combine them however you want.
Using the above-code, if your original arrays were:
int[] array1 = {1, 2, 3, 4};
int[] array2 = {5, 6, 7, 8};
aCombined would then result in [[1, 5], [2, 6], [3, 7], [4, 8]]
Which can be visualized as
[column1/array1, column2/array2]
[1, 5]
[2, 6]
[3, 7]
[4, 8]
Original Answer Below
Why do you need to transform it into arrays? Why not just work with the result set itself?
For instance, if you need to get the marker_id of all of the objects with object_id of 1072, just:
(I just typed this up real quick, and didn’t test it, so I may be missing a semi-colon or the logic may be off a little)