This discussion is archived
7 Replies Latest reply: Aug 23, 2013 5:57 AM by user575089 RSS

data format

user575089 Newbie
Currently Being Moderated

how to store data in this format ?

[[2012,07,01],[2012,07,12]]

 

 

Should I use List of lists to store data  ?  or   what data structure to use here ?

Basically I  have two String values  "2012,07,01"   and  "2012,07,12"

 

I want to store these values in the above format

 

How to do it ?

  • 1. Re: data format
    rp0428 Guru
    Currently Being Moderated

    Why not just use 'Date' datatypes to stored dates?

     

    How to store multiple instances depends on how you plan to use them.


  • 2. Re: data format
    user575089 Newbie
    Currently Being Moderated

    As I said I have two String values as posted above.

     

    What is the solution ?  Can I store data into the required format ?

  • 3. Re: data format
    rp0428 Guru
    Currently Being Moderated

    And as I said:

    How to store multiple instances depends on how you plan to use them.

    You still haven't provided ANY information about what you plan to do with the data once it is stored or how you plan to use the data. Nor have you said how many there are, how often you need to add new ones, whether the data needs to be accessible in any particular order, whether data is ever deleted, etc.

     

    I also said that if they are really dates you should store them as dates.

     

    That will:

    1. prevent invalid data from being stored

    2. be much more efficient

    3. require less space

     

    Please explain what possible value there is in storing the day, month and year as separate components when you apparently don't plan to access the components separately anyway.

     

    Since you will always have three values for each item you could use a size 3 array for the components and a List or HashMap to hold them.


  • 4. Re: data format
    939520 Explorer
    Currently Being Moderated

    As stated in the previous post, its better to store them as Date object types.

    Here is an example storing them in a List:

      List<Date> dates = new ArrayList();

     

    You can also store them as a Set, Map, etc. Search Google for 'Java Collections' to read up on the various tradeoffs for collections and see which one meets your needs.

    Here is one such link:  http://java67.blogspot.com/2013/01/difference-between-set-list-and-map-in-java.html By the way, a collection of dates doesn't mean anything if you dont' store what each date is for. Therefore a key/value Map (person's name/birthdate) may be better than a list.

  • 5. Re: data format
    user575089 Newbie
    Currently Being Moderated

    These are not dates.

    I  have two String values  "2012,07,01"   and  "2012,07,12".

    I want to store these data in the format I posted.

     

    What is the solution ?

     

    >>>>You still haven't provided ANY information about what you plan to do with the data once it is stored or how you plan to >>>use the data.

    ---  Not required in this context.  I need it for some purpose.  data usage is out of scope.

     

    >>>>Nor have you said how many there are, how often you need to add new ones, whether the data needs to be >>accessible in any particular order, whether data is ever deleted, etc.

     

    ---- not required.  don't worry about these  parts.

     

    >>>>I also said that if they are really dates you should store them as dates.

    No. these are not dates.

     

    How to put two String values  "2012,07,01"   and  "2012,07,12".  into  the above data format  ?

  • 6. Re: data format
    rp0428 Guru
    Currently Being Moderated

     

    >>>>You still haven't provided ANY information about what you plan to do with the data once it is stored or how you plan to >>>use the data.

    ---  Not required in this context.  I need it for some purpose.  data usage is out of scope.

     

    >>>>Nor have you said how many there are, how often you need to add new ones, whether the data needs to be >>accessible in any particular order, whether data is ever deleted, etc.

     

    ---- not required.  don't worry about these  parts.

     

    How to put two String values  "2012,07,01"   and  "2012,07,12".  into  the above data format  ?

    Since 'data usage is out of scope' and we don't need to worry about how many there are, adding new ones or deleting any then it doesn't matter how inefficient it might be to actually get the data back out. So just use one giant string to store the data

    "2012,07,01" +  "2012,07,12" + string3 + string4 + . . . + stringn

    You can just concatenate as many strings together as you like until you exceed 2GB or run out of memory.

     

    All other possible solutions are 'out of scope' without having the information previously ask for.

  • 7. Re: data format
    user575089 Newbie
    Currently Being Moderated

    Thanks. This is useful.

     

    There is not much data anyway.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points