Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: URGENT: How do I store thousands of data into arraylists and use them for calculations???

1. ## URGENT: How do I store thousands of data into arraylists and use them for calculations???

Hey guys, I'm doing this really complex problem from a past exam paper (got my real exam next monday!!!) which requires us to store thousands of data into array lists and do some calculations with them like mean, standard deviation etc...

The data is to be extracted from a URL - this I can do easily.

The data in the URL contains approximately 10,000 values individually for x (height), y (weight) and another column for Group.
(Sorry I can't post the link here since its an internal university link which can only be accessed by students....)

Rough Example...

Group, x (height, metres), y (weight, kg)
1, 1.61, 77
2, 1.56, 56
3, 1.58, 66
4, etc...etc...

Now heres the catch: some x and y values have the same Group numbers so:

Group 1 has some x and y values associated with it, Group 2 has some x and y values associated with it and so on...There are 100 Groups in total. But the thing is, the whole data set in the URL is not in order....

Now how do I store all of this data in a single N x 3 array and calculate the mean x and y values for each Group 1,2,3,4,5 -> 100 ?

Heres some data points for visualisation:

Group, x, y
2, 1.44, 56
2, 1.55, 66
3, 1.65, 65
6, 1.83, 85
6, 1.71, 78
3, 1.78, 89
3, 1.67, 67
3, 1.49, 52
5, 1.71, 72
5, 1.52, 61
8, 1.98, 103
8, 1.67, 90
1, 1.76, 85

Any help or advice would be greatly appreciated.

2. ## Re: URGENT: How do I store thousands of data into arraylists and use them for calculations???

Why do you have to store it in an array? If it's because this is an assignment, then you'll have to provide some more information: what have you tried? How would you do this by hand, with a piece of paper and a pencil?

I would just use a Map.

3. ## Re: URGENT: How do I store thousands of data into arraylists and use them for calculations???

Originally Posted by KevinWorkman
Why do you have to store it in an array? If it's because this is an assignment, then you'll have to provide some more information: what have you tried? How would you do this by hand, with a piece of paper and a pencil?

I would just use a Map.

Actually you can use any method you like for the assignment.

I've tried using individual array list for each of the data.

I used a for loop to sort each x and y values to the specified group using .collections(), but this is taking a very long time and a lot of code to do..

When you say map do you mean HasMap?

Could you please show me an example on how I would go about doing that?

4. ## Re: URGENT: How do I store thousands of data into arraylists and use them for calculations???

Recommended reading: The Map Interface (The Java™ Tutorials > Collections > Interfaces)