Results 1 to 6 of 6

Thread: Table or Map in Collection

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Table or Map in Collection

    Hello,
    I have a table in DB that contains the code for an action in the stock market, date and value of this action to date. I want a simple structure, with, if we consider a table, an action line. Style a table of 6 columns with the code share, the value today, the value of last month, the value. I immediately thought of a table, but is that what are faster in Java? Then I'll have to easily access the values of a share from its code. So I need some kind of index on the action code, that's why I thought of a Map. I tell myself I can do a Map containing the key code of the action and enhance an array of 5 values of my action:
    Code:
    MAP:
    key | value
    13244 | [4.0, 2.0, 7.44, 12, 74]
    I can also replace the table with a Map, and have a Map of Map:
    Code:
    MAP:
    key | value
    13,245 | MAP (AUJ -> 5.0 yesterday -> 2.0, last month -> 7.45, ...-> 12 ...-> 74)
    But I do not see the point. I think it's a problem that is often faced, having to store data from a database in a table or a Map and would like your opinion on my idea Map (key, table).

  2. #2
    Join Date
    Dec 2009
    Posts
    192

    Re: Table or Map in Collection

    Hello,
    Array (or List) ==> to use lists 'ordered'. Map ==> to use pairs of key / value can easily find a particular value. The table may be quicker to access an item, but if you must go half the table to find a particular item is useless. To me your Solution Map (key | table) seems correct. The Map allows you to access a particular action quickly. The table allows you to display different dates, especially if these different times are identical as seems to be the case. You could opt for a Map Map of whether these dates vary.

  3. #3
    Join Date
    Nov 2009
    Posts
    518

    Re: Table or Map in Collection

    Hello,
    As you program is in Java, why do not you object? Instead of storing your actions in a table with 6 columns, you should put them into objects. You see, it's much easier to read and change: a name attribute is even more telling when an index table. Translated into object language mean. You note similarity with your proposal to make a Map of Map of names for speakers. Afterwards, as stated in the above post, you can store your Action objects in a table or in a map according to your needs.

  4. #4
    Join Date
    Dec 2009
    Posts
    292

    Re: Table or Map in Collection

    Hello,
    Even I wanted a solution for this, I thought about that possibility but I wonder if in terms of performance it is no more expensive to create a specific object to handle this and if so, what is the cost. If it's insignificant, who cares, but if the access time is multiplied by 5 or 10, it can be embarrassing. On this point, I confess that my knowledge is limited, I have some ideas on performance on access.

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: Table or Map in Collection

    Hello,
    I'm not an expert on the subject. But I think it is possible that access to attribute class are a bit longer than an element of an array.
    Just write a small program that verifies:

    - fill a table with 1 row and n columns;
    - it fills an object with n attributes of same type as the array elements;
    - It is like 100 000 to access the columns, we look at how long it takes;
    - And it does it again by accessing the attributes of the object.

    Now, it does not necessarily watch the performance at any price. Especially on a small number of accesses the difference will be minimal. When you see the flexibility is gained, in my opinion where the picture is better is very marginal. In addition, an array contains elements that only one type, while in your object, you can store anything you want: if one day you have new needs, such as storing more the wording of the Action.

  6. #6
    Join Date
    Dec 2009
    Posts
    202

    Re: Table or Map in Collection

    Hello,
    It is true that the flexibility and clarity of the code are things primordial. I also think they should (although I do not do it all the time but I will force myself a bit!) More often construct objects to model data structures (as we have a database create objects that represent the data tables). Code maintenance is really easy because the code is much clearer, even if at that moment it feels to lose a little time. And then it can be much more flexible if it wants to modify the database behind. Thank you for your thoughts, I think I'm going to force a little more to create objects for a code really clean, because it is often more important than pure performance (which is necessary in rare applications) .

Similar Threads

  1. Replies: 5
    Last Post: 27-08-2011, 10:53 AM
  2. Link a Table to another Table to Drop Down In Main Table
    By himeshRES in forum Windows Software
    Replies: 6
    Last Post: 11-12-2010, 02:01 PM
  3. Replies: 4
    Last Post: 30-11-2010, 03:01 AM
  4. To convert a pivot table to a flattened table in MS Excel
    By zeemga in forum Windows Software
    Replies: 3
    Last Post: 27-11-2010, 06:48 AM
  5. How to copy one table data into another table directly?
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 22-09-2009, 03:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,055,689.79776 seconds with 17 queries