Results 1 to 12 of 12
  1. #1
    House's Avatar
    House is offline Member
    Join Date
    Aug 2010
    Posts
    17
    Rep Power
    0

    Exclamation How Useful Are Arrays ?

    Hi Guys

    I was wondering, how actually useful are Arrays ? I mean I can think of 1000s of Apps where one needs collections, but in all cases I find writing and retreaving data from a database more logical than using an Array !!

    Where exactly do Arrays come to their own league and are the best logical solution ?

    I was thinking of building a Note Apps, but it seems more logical to use a database for storing the notes !!

    I'd appreciate some comments and corrections for my opinion of Arrays !

    Thank You.
    " It does not matter how slowly you go so long as you do not stop. ".... Confucius

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Arrays can be useful if you have n elements of type T and you have to manipulate them. The value of n has to be fixed before you do the manipulations and the type T also has to be known in advance and the manipulation of the elements can't be done sequentially. To most people new to programming arrays are the one size fits all data structure and they cram and abuse their programs and logic to be able to use arrays. Arrays have their (limited) use.

    kind regards,

    Jos

  3. #3
    House's Avatar
    House is offline Member
    Join Date
    Aug 2010
    Posts
    17
    Rep Power
    0

    Default

    Abuse >> Exactly !!

    Can you tell me a project example, of when Array would be better use than a Database ?

    Thanks
    " It does not matter how slowly you go so long as you do not stop. ".... Confucius

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by House View Post
    Can you tell me a project example, of when Array would be better use than a Database ?
    I'm not sure how to answer this question since use of arrays and database are not mutually exclusive. They are both used for very different reasons.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by House View Post
    Abuse >> Exactly !!

    Can you tell me a project example, of when Array would be better use than a Database ?

    Thanks
    Erm, a Sudoku solver? A couple of 9x9 arrays can do the job faster than database access. Matrix manipulations, any fixed set of homogenous types T, etc. Databases come with their (non trivial) overhead.

    kind regards,

    Jos

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    ?
    I write Java code that accesses databases...that's my job.
    I cannot think of one project I have been on whereby I did not need collections (ie arrays).

    What on earth do you expect to do with the result of the following query if not stick it in a collection??
    "SELECT * FROM my_table"

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    What on earth do you expect to do with the result of the following query if not stick it in a collection??
    "SELECT * FROM my_table"
    A Collection is fine, but just an array? For one thing: you need to know the number of rows in the ResultSet in advance to be able to create an array of exactly that length ...

    kind regards,

    Jos

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I'm not convinced the OP wa simply talking about arrays...he does mention collections as a general term.

    In any case, arrays tend to back most Lists, so the ArrayList I stick most of my results into is simply a convenient front end to an array.

  9. #9
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default Arrays needed for quicksort

    The fastest single processor
    sort method is quicksort.

    Quick sort implements an array
    to perform its sort.

    I have a wireframe editor project
    that holds its data in a
    linked-list. This simplifies the
    implementation of the project's
    editing functions.

    I needed a fast method to
    re-order the triangles in
    wireframe models according to
    their Z coordinates.

    So I implemented an array of
    linked-list referrences in a
    quicksort method. The results
    is exceptional.

    Moral:
    The fastest single processor
    data sorting algorithm in
    computer history requires an
    array to perform.
    Last edited by paul pasciak; 09-03-2010 at 09:14 PM. Reason: Re-phrased for continuity and clarity

  10. #10
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    how random of you

  11. #11
    XmisterIS is offline Member
    Join Date
    Aug 2010
    Posts
    35
    Rep Power
    0

    Default

    As others have said, I'm finding them useful for things that don't change their size.

    For example, I'm writing an application that has a calendar in it and an object for each month of the year. Now, unless the moon falls into the sea, there will always be twelve months in each year!

    Therefore, it's easier for me to use an array than a vector.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

Similar Threads

  1. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM
  2. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  3. Arrays
    By hypes057 in forum New To Java
    Replies: 13
    Last Post: 09-04-2009, 10:40 AM
  4. Arrays
    By HosHos in forum New To Java
    Replies: 3
    Last Post: 08-14-2009, 04:23 AM
  5. Need help with Arrays
    By dietgal in forum New To Java
    Replies: 21
    Last Post: 10-08-2008, 01:59 PM

Posting Permissions

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