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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    Many thanks in advance.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Quote Originally Posted by KevinWorkman View Post
    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. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] ArrayLists - Getting index of parameters of objects of ArrayLists.
    By mwebb in forum Object Oriented Programming
    Replies: 1
    Last Post: February 16th, 2012, 07:39 PM
  2. User input and calculations problems
    By javabeg123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 7th, 2011, 07:32 PM
  3. array to store multiple names and data
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 05:03 AM
  4. arraylists to store coordinates for a snake applet
    By finalfantasyfreak15 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 19th, 2011, 10:21 PM
  5. Replies: 1
    Last Post: May 3rd, 2010, 01:03 PM