Results 1 to 4 of 4
  1. #1
    riddhik84 is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Unhappy Difference between Arraylist and Vector in abstractTableModel ?

    I know there is a difference between Arraylist and Vector by theory. But I dont know if there will be any difference if I use either Arraylist or Vector in AbstactTableModel.

    For ex:
    --> Use of Array:
    public class TabSeachModel extends AbstactTableModel
    {
    private String[][] rowData = {
    {"001", "hello"}
    };
    public int getRowCount()
    {
    return rowData.length;
    }

    }

    --> use of Vector
    public class TabSeachModel extends AbstactTableModel
    {
    Vector rowData = new Vector(11);
    public int getRowCount()
    {
    return rowData.size();// dont know size or length...
    }

    }


    --> use of arraylist
    public class TabSeachModel extends AbstactTableModel
    {
    ArrayList<type> rowData = new ArrayList<type>(11);
    public int getRowCount()
    {
    return rowData.size();// dont know size or length...
    }

    }



    What will be the difference between all three with the reference to AbstractTableModel only.

    I mean will it happen at any time like if the number of rows increase by too many, and if I use vector then it will sometimes show me memory error as vector increase double each time...

    Thanks.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    There should be no difference between using a Vector or an ArrayList in a TableModel.

  3. #3
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    5

    Default

    Quote Originally Posted by camickr View Post
    There should be no difference between using a Vector or an ArrayList in a TableModel.
    There is a big difference between Vector and ArrayList concerning the matter of multi-threading. I'm not well acquainted with Swing, but I presume this difference would affect the TableModel as well.

    AraryList is not synchronized.

    Quoting the ArrayList API, "Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally".

    Vector, on the other hand, IS synchronized, so no external synchronization is necessary.

    If you are dealing with single thread applications, AraryList will probably perform slightly better. However, if you are multi-threading, Vector should be used, since it's already synchronized.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    There is a big difference between Vector and ArrayList concerning the matter of multi-threading. I'm not well acquainted with Swing, but I presume this difference would affect the TableModel as well.
    When updating Swing components of models of the components the updates should be done on the EDT, which takes threading issues out of the picture. The performance benefits of ArrayList over Vector are minimal at the best of times and will be of no consequence when used in a table as far more time will be spent renderering the cell.

    The OP stated that they know there is a difference in theory, but in the context of the original question I maintain there is no difference.

Similar Threads

  1. what is the difference
    By ron87 in forum New To Java
    Replies: 5
    Last Post: 01-04-2011, 04:31 PM
  2. Replies: 1
    Last Post: 04-06-2009, 06:45 AM
  3. Replies: 4
    Last Post: 04-01-2009, 02:03 AM
  4. Replies: 2
    Last Post: 04-21-2008, 11:43 AM
  5. Difference between ASP and JSP
    By barney in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 07:15 AM

Posting Permissions

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