In Java I am wondering how to sort vectors of vectors on a particular column where one vector is used as a row and one vector is used to hold all the row vectors e.g.
Vector row = new Vector();
Vector main = new Vector();
row.add("Column1");
row.add("Column2");
row.add("Column3");
main.add(row);
Then sort the variables in one of the columns e.g. Column2.
Thank you
You could write a
Comparator<Vector>that compares twoVectorobjects based on their second element and useCollections.sort(List,Comparator)with that.But in the long run you’ll be much better off if you get rid of the
Vector-in-Vectorconstruct and replace the innerVectorwith a custom class that represents the data that you want it to represent. Then you’d write aComparator<MyClass>which would be much easier to interpret (“oh, this comparator compares based on the first name” instead of “why does this comparator take the element at index 1 and compare that? What does that mean?”).