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:
Code :
public class TabSeachModel extends AbstactTableModel
{
private String[][] rowData = {
{"001", "hello"}
};
public int getRowCount()
{
return rowData.length;
}
}
--> use of Vector
Code :
public class TabSeachModel extends AbstactTableModel
{
Vector rowData = new Vector(11);
public int getRowCount()
{
return rowData.size();// dont know size or length...
}
}
--> use of arraylist
Code :
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.
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.
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.
Quote:
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