Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Difference between Arraylist and Vector in abstractTableModel ?

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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.
    Last edited by helloworld922; November 7th, 2009 at 02:22 AM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Difference between Arraylist and Vector in abstractTableModel ?

    The difference between arrays and ArrayList is pretty much non-existent, since by definition arrays are lists, and ArrayList simply means it's a list implemented with an array. ArrayList does provide a nice little feature, though. It will automatically expand it's size where as arrays won't by themselves (done by creating a new array and moving everything over, just as an array would, but it's "automatic").

    I'm not sure what the underlying implementation of Vector is, but it looks like it's also implemented with an array (due to the "capacityImcrement" variable). The one crucial difference between ArrayList and Vector is that the Vector class is synchronized, while ArrayList is not. Arrays I believe by default are also non-synchronized, though they're simple enough that you can implenent the synchronization yourself.

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Difference between Arraylist and Vector in abstractTableModel ?

    ArrayList = New improved Vector without synchronisation, its fast, its what you want most of the time if not all of the time.
    Vector = The old and slow version of holding scalable arrays, its synchronised.

    Basically the difference is just like it says in the API.

    As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized.
    If you for some reason would like a synchronised list you can use the Collections.synchronizedList method. See Collections (Java Platform SE 6))

    // Json

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 04:44 AM
  2. Arraylist or Arraylist Object?
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: September 11th, 2009, 03:08 AM
  3. byte[] from vector
    By perlWhite in forum Collections and Generics
    Replies: 1
    Last Post: August 26th, 2009, 06:10 AM
  4. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 02:11 PM
  5. vector
    By sriraj.kundan in forum Java Theory & Questions
    Replies: 8
    Last Post: August 12th, 2009, 11:17 AM