David
David

Reputation: 155

How to sort a Vector from a spesific index

We have such method for array

Arrays.sort(Object[] a, int fromIndex, int toIndex);

but to sort a Vector there is only a method using comparator

Vector.sort(Comparator c)

is there any way to sort a vector but using only fromIndex and toIndex?

Upvotes: 0

Views: 46

Answers (1)

Higigig
Higigig

Reputation: 1265

First of all, Vector isn't used that much. Use ArrayList. But to sort a Vector, use this:

Collections.sort(myVector.subList(startIndex, endIndex));

It will change the original Vector too.

Upvotes: 1

Related Questions