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 8872495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:14:06+00:00 2026-06-14T18:14:06+00:00

I have two different arrays an ArrayList of doubles and an Array of Strings

  • 0

I have two different arrays an ArrayList of doubles and an Array of Strings

 public class tester {

        private final static String TIME[]={ "8:00", "9:00", "10:00", "11:00", 
            "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00"  };


        public static void main(String[] args){
            ArrayList<Double> stat = new ArrayList<>();
            stat.add(1.0);
            stat.add(2.0);
            stat.add(3.0);
            stat.add(4.0);
            stat.add(5.0);
            stat.add(6.0);
            stat.add(7.0);
            stat.add(8.0);
            stat.add(9.0);
            stat.add(10.0);
            stat.add(11.0);
            stat.add(12.0);
            int i = 0;
            for (String time : TIME) {
                System.out.println(time+" "+stat.get(i));
                i++;
            }

My question is quite simple is this the best way to loop through each array if I want to get the same position of each array to match? so that stat.get(0) ==TIME.get(0)?

Update

First of all thank you all for your quick response i like the idea of creating a class however there is something you need to know.

The thing you saw was a test class that i use to test my data.

i KNOW that the two arrays will ALWAYS be the same size due to the fact that the stat ArrayList normally defined like the following:

stat is a calculated value of data gained from the database the value of stat is based on time and then sent back to the GUI to be put into a graph and a table.

This means that for each of the TIME there is an exisiting value so that stat.get(0) is ALWAYS equal to TIME.get(0) == “8:00”.

With this in mind do you still think i should create a class or should i keep the class showed below and then add a HashMap containing the data then iterate over that map to insert the data in my GUI?

public class Statistics {
    private ArrayList<CallQueue> queues = new ArrayList<CallQueue>();
    private ArrayList<Double> averageData = new ArrayList<Double>();
    private Provider p;

    public Statistics(){
         try {
            this.p = new Provider();
        } catch (DopeDBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    /**
     * This recursive method calculates the average of each time table and then adds its to the arrayList in the following order:
     * 8.00  = 0
     * 9.00  = 1
     * 10.00 = 2
     * 11.00 = 3
     * 12.00 = 4
     * 13.00 = 5
     * 14.00 = 6
     * ect.
     * @param time
     */
    public void calculateAverage(){
        int data = 0;
        for (int i = 8; i < 20; i++) {
            for (CallQueue cq : queues) {
                data += cq.getCallsByTime(i);
            }
            if (data == 0) {
                Main.createErrorMessage("Fejl i dataen! \r\n kontakt venligst ansvarlige i Dope");
            }
            averageData.add((double) data/11);
        }
    }
    /**
     * @author MRCR
     * This method recives the object list from the database and sets the currentlist to the list recived.
     */
    public void setQueues(Calendar start, Calendar end){
        try {
            queues = p.getInformation(start, end, queues);
        } catch (DopeDBException e) {
            // TODO Auto-generated catch block
            Main.createErrorMessage("Message");
        } catch (DopeResultSetException e) {
            // TODO Auto-generated catch block
            Main.createErrorMessage("Message");
        }

    }
    /**
     * This method returns the calculated DataList list.
     * @author MRCR
     * @return averageData
     */
    public ArrayList<Double>getData(Calendar start, Calendar end){
        setQueues(start, end);
        calculateAverage();
        return averageData;
    }



}


import java.util.HashMap;


public class CallQueue {
    private String type;
    private HashMap<Integer, Integer> data = new HashMap<Integer,Integer>();
    public CallQueue(String type){
        this.type = type;
    }
    public String getType(){
        return type;
    }
    public int getCallsByTime(int time){
        return data.get(time);

    }
    public void addCallsByTime(int hourOfDay, int callAmount) {
        data.put(hourOfDay, callAmount);

    }

}
  • 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-14T18:14:07+00:00Added an answer on June 14, 2026 at 6:14 pm

    I would first check that the lengths of the 2 arrays are the same.
    Then iterate using a for loop:

    final int timeLength = TIME.length;
    if (timeLength != stat.size()) {
        //something may not be right
    }
    for (int i = 0; i < timeLength; i++) {
        System.out.println(time[i]+" "+stat.get(i));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different arrays, one with strings and another with ints. I want
I have two different arrays. One array, a, for a list of people. My
If I have two different arrays and all I can do is check whether
I'm trying to come up with a way combine two arrays that have different
Is it possible to have an array that contains two different types of data?
I have two arrays (or arraylists if it is easier) of strings. I need
Hey guys. I have a question. I have two different arrays with different structure
I have two arrays of different size A and B. I am comparing A
I have two different arrays like this var images = [{ src: images2/animal_1.jpg, title:
I have two arrays of the alphabet which have been sorted in two different

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.