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

  • Home
  • SEARCH
  • 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 7944205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:29:10+00:00 2026-06-04T00:29:10+00:00

i have an ArrayList that looks like this: [ 1 2011-05-10 1 22.0, 2

  • 0

i have an ArrayList that looks like this:

[
1 2011-05-10  1  22.0, 
2 2011-05-10  2  5555.0, 
3 2011-05-11  3  123.0, 
4 2011-05-11  2  212.0, 
5 2011-05-30  1  3000.0, 
6 2011-05-30  1  30.0, 
7 2011-06-06  1  307.0, 
8 2011-06-06  1  307.0, 
9 2011-06-06  1  307.0, 
10 2011-06-08  2  3070.0, 
11 2011-06-03  2  356.0, 
12 2011-05-10  2  100.0, 
13 2011-05-30  1  3500.0, 
14 2011-05-10  3  1000.0, 
15 2011-05-10  3  1000.0, 
16 2011-05-07  1  5000.0, 
17 2011-05-07  4  500.0, 
18 2011-08-07  3  1500.0, 
19 2011-08-08  6  11500.0, 
20 2011-08-08  4  11500.0, 
21 2011-08-08  7  11500.0, 
22 2011-06-07  8  3000.0]

Here is the code how i got this arraylist:

@Override
    public ArrayList<Expenses> getExpenses() {
        ArrayList<Expenses> expenses = new ArrayList<Expenses>();
        try {
            Statement stmt = myConnection.createStatement();
            ResultSet result = stmt.executeQuery("SELECT * FROM expenses");
            while(result.next()){

                Expenses expense = new Expenses();
                expense.setNum(result.getInt(1));
                expense.setPayment(result.getString(2));
                expense.setReceiver(result.getInt(3));
                expense.setValue(result.getDouble(4));

                expenses.add(expense);

                }
        }
            catch (SQLException e){
                 System.out.println(e.getMessage());
             }
        return expenses;
    }

but what i want to get to an arraylist so that each element of array wasn’t the line of the table (what i have now), but every individual element of the table should be the element of array ( [1, 2011-05-10, 1, 22.0, 2, 2011-05-10, 2, 5555.0, 3, 2011-05-11, 3, 123.0,]. Can anyone help me with that?

  • 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-06-04T00:29:11+00:00Added an answer on June 4, 2026 at 12:29 am

    The only way you could do add into an ArrayList elements of different type, will be to treat them as general objects. However the code you already have is much superior.

    @Override
    public ArrayList<Object> getExpenses() {
        ArrayList<Object> expenses = new ArrayList<Object>();
        try {
            Statement stmt = myConnection.createStatement();
            ResultSet result = stmt.executeQuery("SELECT * FROM expenses");
            while(result.next()) {
    
                expenses.add(new Integer(result.getInt(1)));
    
                expenses.add(result.getString(2));
                expenses.add(new Integer(result.getInt(3)));
                expenses.add(result.getDouble(4));
            }
        }
        catch (SQLException e) {
            System.out.println(e.getMessage());
        }
        return expenses;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class, and list of instances, that looks something like this (field
I have a String with an unknown length that looks something like this dog,
I have a xml file that looks like this <a> <bb> <c date=20110706 time=1:20
I have a String that looks like this String read = 1130:5813|1293:5803|1300:5755|1187:5731| As you
So I have a file that looks like this: 1st 2nd­ nth e1­, ­­v1,
So currently, I have an ArrayList that looks something like: [ [id, type, name,
I have an html form that looks something like this: <div class=field> <input id=product_name
I have a file that looks like this: 1st ­ ­ ­ ­­­ 2nd
I have structs like below and when I do that initialization: ArrayList nodesMatrix =
I want to split a string in C#.NET that looks like this: string Letters

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.