Re: Question About LinkedList

From: Edward H. Fabrega (spiritualfields_at_charter.net)
Date: 09/23/04


Date: Thu, 23 Sep 2004 11:57:41 -0700


"John C. Bollinger" <jobollin@indiana.edu> wrote in message
news:ciusev$g9k$1@hood.uits.indiana.edu...
> You have not even come close to specifying all your requirements. I
> suspect that the term "database" has a very specific meaning to you, at
> least in this context, but it does not illuminate us very well. Enumerate
> (for yourself) all the functional requirements, and determine how well
> your proposed model will handle them. If you need help with such an
> evaluation then ask some more specific questions here.
>
> To get you going, here are some of the key characteristics of the two main
> List implementations:
>
> ArrayList
> ---------
> ()Indexed element access is fast (constant time).
> ()List additions (at the end) sometimes require copying the entire backing
> array (to a larger array), but usually not. Adding a large number of
> elements is O(log N), if I've worked it out right.
> ()List insertions (not at the end) require moving the elements at and
> after the insertion position, and sometimes requires moving all the
> elements (when a larger array is required).
> ()List deletions usually require moving some or all of the elements of the
> backing array to new positions (O(N)).
>
> LinkedList
> ----------
> ()Indexed element access is slow (O(N) for random indices) because the
> List must be traversed from one end to the desired element. The specific
> cases of access to the first and last elements are fast, however.
> ()Additions and deletions at beginning or end are O(1)
> ()_Indexed_ additions and deletions are O(N) for random indices, because
> of the time required to traverse the list to the appropriate location.
> ()List mutations never require copying the backing data structure.
> ()The List's ListIterator is your friend. Use it instead of indexes
> wherever possible.

Thanks for that information. It looks like an ArrayLists of ArrayLists is
better than a LinkedList of ArrayLists. What my goal is is to write a
database program, similar to the one I wrote a couple of years ago in C++
MFC:

http://members.aol.com/spiritualfields/index.htm

The screenshots will give you a good idea of the view. It looks like a
JTable will work for the UI. I'm not even close to coding yet, as I'm
familiarizing myself with the java language and the jdk api. The underlying
data model that I had used for MyAuctionHelper was a linked list of
StringArrays. The view was modeled after Access, but I didn't use a
component, I painted it myself and coupled it to the database, but I do not
want to go through that again. The only constraint that I can think of right
now is that the data structure must compatible with JTables, and unless I'm
wrong, an ArrayLists of ArrayLists works with the JTable(Object[][] ,
Object[]) constructor. This will be a standalone application, and not
necessarily a remake of my previouis program. Between now and when I
actually start coding I could get other ideas. What is absolutely essential
is that the database is completely encapsulated so I can resuse it. I could
be wrong, but it looks like the javax.swing api almost forces encapsulation
if I use JTables as the view. I'm not sure if I have any more questions
explicitly, I'm still learning the nuts and bolts of java. If you have any
ideas or insights on modeling databases (flat file) with java, I'll be
interested to hear them.



Relevant Pages

  • an Array of ArrayLists in Java 5
    ... The following code snippet worked fine in Java ... I'm setting up an array of ArrayLists. ... The following code is generating a compiler time warning. ...
    (comp.lang.java.programmer)
  • Re: Question About LinkedList
    ... >> Using MFC I was able to do this with a linked list of StringArrays. ... > database that is ..." ... I can't do an array of arrays because the database ... the ArrayLists in the LinkedList, and the size of the LinkedList itself that ...
    (comp.lang.java.programmer)
  • Re: Reflection Performance Question.
    ... Something that does the gruntwork at design time rather than at runtime. ... Regarding arrays vs. arraylists -- arrays hold items of a specific data ... but arraylists are lists of objects and thus you have boxing / ... overhead is significant, so if you can live with an array, it's a good way ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Grid in ASP.Net like Windows Forms
    ... Hey Alfredo. ... Array vs. ArrayList ... I often use ArrayLists to get my data initially, ... I would say these type of objects are better to session than viewstate. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How memory stacks up.
    ... >> overhead), and then 1,000,000 ArrayList objects, each of which has its ... >> bytes for the single null reference). ... million arrays of length 1 and one array ... not for the ArrayLists themselves. ...
    (microsoft.public.dotnet.languages.csharp)