Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7626607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:20:52+00:00 2026-05-31T05:20:52+00:00

my java is rusty and I was wondering if someone could give me a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:20:53+00:00Added an answer on May 31, 2026 at 5:20 am

    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.

        //get the size of the ResultSet
        myResultSet.last();
        int resultSetSize = myResultSet.getRow();
        //initialize your arrays to be joined
        int[] array1 = new int[resultSetSize];
        int[] array2 = new int[resultSetSize];
       //loop through the result so array1 will be the same as column1 of your table, etc.
        int count = 0;
        myResultSet.beforeFirst();
        while (myResultSet.next()){
            array1[count] = myResultSet.getInt("my column 1");
            array2[count] = myResultSet.getInt("my column 2");
            count++;
        }
        //declare rows and columns for easy code readability
        int row = 0;
        int column = 2;
        //set your combined array row and column lengths
        int[][] aCombined = new int[array1.length][column];
        //reset your column value to put array1 down column 0
        column = 0;
        for (int tempInt : array1){
            aCombined[row][column] = tempInt;
            row++;
        }
        //reset your row and go to the next column to do the same as above
        row = 0;
        column = 1;
        for (int tempInt : array2){
            aCombined[row][column] = tempInt;
            row++;
        }
    

    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:

    public ArrayList getMarkerID(int objectId){
         ArrayList<int> myArrayList = new ArrayList<>();
         myResultSet.beforeFirst();
         while (myResultSet.next()){
             if (myResultSet.getInt("object_id") == objectId){
                  myArrayList.add(myResultSet.getInt("marker_id"));
             }
          }
          return myArrayList;
      }
    

    (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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to convert some C/C++ code to Java. My C++ is extremely rusty.
Java Code In Java code I have class called IdentificationResult which has 3 members:
My C++ is a little rusty having worked in Java and C# for the
My knowledge of Java is rather rusty, but I've been forced to use it
I'm just starting out on android and my java is verry rusty. I can't
Do you agree that the designers of Java class java.io.IOException should have made it
I am trying to write some simple numerical code in Java where one can
This is something I used to do in Java, I was wondering if there
First off my Java is beyond rusty and I've never done JSPs or servlets,
Java Code: import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegExpTest { public static void main(String[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.