Results 1 to 4 of 4
- 11-07-2009, 06:44 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
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.
- 11-07-2009, 06:57 AM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
There should be no difference between using a Vector or an ArrayList in a TableModel.
- 11-07-2009, 08:24 AM #3
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
- 11-07-2009, 05:25 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
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.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.
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
-
what is the difference
By ron87 in forum New To JavaReplies: 5Last Post: 01-04-2011, 04:31 PM -
Vector<Point2D> list = new Vector<Point2D>();Is it possible for 15,000 Point2D obj???
By Mazharul in forum Java 2DReplies: 1Last Post: 04-06-2009, 06:45 AM -
Problem when adding values of the ResultSet to a AbstractTableModel
By Azuxard in forum AWT / SwingReplies: 4Last Post: 04-01-2009, 02:03 AM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
Difference between ASP and JSP
By barney in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-07-2007, 07:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks