Results 1 to 6 of 6
  1. #1
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    167
    Rep Power
    9

    Default Storing set of numbers in an array?

    Hello everyone,

    I am looking for some directions. I trying to write a piece of code which takes a set of numbers or even data type and stores in an array (or you may suggest something more suitable).

    For example:
    Date N1 N2 N3 N4 N5 Day
    10/11/2012 10 09 32 100 15 Thursday
    11/12/2013 01 0 0 23 50 51 Tuesday

    I'd like to be able to sort them so that if I want to search for one of the entries, I can then create a function which allows me to sort them by date or even return all the numbers by a given date or day, etc....

    However, I'd like to be able to set it up so that each set is "linked" meaning that again that I can search by date and it returns everything at that date.

    I wanted to use an array but I don't know:
    -How to do it?
    -Whether this is a suitable approach?

    I am looking for some directions, best practice, etc... Array vs. something else?

    Thanks,
    bigsonny

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Storing set of numbers in an array?

    There are lots of design considerations here. First, you need to familiarize yourself with
    Lists (ArrayList, LinkedList, etc) and Collections. You could have your own date object (although
    some JDK classes may work fine). You can then use the Collection.sort method and supply your
    own sorting criteria. You can also use the "date" object as part of a larger collection of objects
    which could be use as a filter taking a range or specific date. You could do this using a simple CLI
    or perhaps incorporate it into a JList for a more advanced effect.

    You might also want to use an input verifier of some sort to control how the date is entered.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Storing set of numbers in an array?

    Quote Originally Posted by bigsonny View Post
    Date N1 N2 N3 N4 N5 Day
    10/11/2012 10 09 32 100 15 Thursday
    11/12/2013 01 0 0 23 50 51 Tuesday
    I assume this example is significant: 10/11/2012 is indeed a Thursday, and (so) 11/12/2013 is a Tuesday; that makes the last column functionally dependent on the first column, so you don't need it. The int numbers in the other columns aren't unique (per row) so you can't use a Set<Integer> or a BitSet for those columns;either an array or List<Integer> or even a Map<Integer, Integer> can represent a single row.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    167
    Rep Power
    9

    Default Re: Storing set of numbers in an array?

    Thank you Jim and Jos. Since I am not familiar with any of these things, I'll get going on my reading and tutorials. Thanks for giving me a starting point.

  5. #5
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    167
    Rep Power
    9

    Default Re: Storing set of numbers in an array?

    Quote Originally Posted by JosAH View Post
    I assume this example is significant: 10/11/2012 is indeed a Thursday, and (so) 11/12/2013 is a Tuesday; that makes the last column functionally dependent on the first column, so you don't need it. The int numbers in the other columns aren't unique (per row) so you can't use a Set<Integer> or a BitSet for those columns;either an array or List<Integer> or even a Map<Integer, Integer> can represent a single row.

    kind regards,

    Jos
    Jos,

    you are correct that the day depends on the date. and the example is significant.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Storing set of numbers in an array?

    Quote Originally Posted by bigsonny View Post
    Jos,

    you are correct that the day depends on the date. and the example is significant.
    Many people make the mistake that they store an easily computable functionally dependent column in a database; the day of the week is functionally dependent on the date (so you don't need to store it in a database; you can easily compute, or generate, it again if needed).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Storing unique random numbers
    By ajw1993 in forum New To Java
    Replies: 6
    Last Post: 04-10-2013, 03:23 PM
  2. Storing random numbers into a String field
    By ajw1993 in forum New To Java
    Replies: 1
    Last Post: 03-23-2013, 05:25 PM
  3. I need help storing numbers in loops
    By MrPosotive in forum New To Java
    Replies: 26
    Last Post: 10-10-2012, 05:55 AM
  4. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 2
    Last Post: 03-30-2011, 06:46 AM
  5. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 11-18-2010, 05:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •