Reputation: 15702
I have created a Vector object to store data in Table
object as Vector<Table>
. Vector<Table>
contains components as below.
[Vector<Record> records, String tableName, String keyColumnName, int recordCount, int columnCount]
I need to sort tableName
in above Vector to my own order and return Vector<Table>
with sorted tableNames
for other processes.
How could i do this ?
UPDATED
I have wrote method as below.
private Vector<Table> orderTables(Vector<Table> loadTables) {
ArrayList<String> tableNames = new ArrayList<String>();
for (Table table : loadTables) {
String tblName = table.getTableName();
tableNames.add(tblName);
}
Collections.sort(tableNames, new MyComparable());
return null;
}
But i have no idea about how to write Comparator
to this. My own sort order is stored in .properties
file. i can read it and get value. but i have no idea about how to compare it.
How could i do it ?
Upvotes: 0
Views: 3990
Reputation: 1866
Just trying to give a pseudocode
TableComparator implements Comparator{
int compare(Table source, Table destination){
//implement your own custom logic of comparison
}
}
Vector<Table> vectorTable = new Vector<Table>();
TableComparator tableComparator = new TableComparator();
Now use this comparator in Collections.sort(vectorTable,tableComparator);
Upvotes: 0
Reputation: 420951
I suggest you use Collections.sort
with your own, custom, Comparator
.
Upvotes: 8