![]() |
VOOZH | about |
The Vector class implements a growable array of objects. Vectors basically fall in legacy classes but now it is fully compatible with collections. It is found in java.util package and implements the List interface, so we can use all the methods of List interface here. This program is used to Sort the 2D array Across Left Diagonal. We will use the concept of vector to sort Left Diagonal prior to which refer to below illustration as follows.
Illustration: Creating a Vector
Vector(): Creates a default vector of the initial capacity is 10.
Vector<E> v = new Vector<E>();
Algorithm:
Now let us discuss functions that will be used in the above approach prior to landing upon the implementation part.
A. removeAll(): The java.util.vector.removeAll(Collection col) method is used to remove all the elements from the vector, present in the collection specified.
Syntax:
Vector.removeAll(Vector);
B. Collections.sort(): This method is used to sort the vector.
Syntax:
Collections.sort(Vector) ;
C. add(): It to add elements in the vector.
Syntax:
Vector.add(value) ;
D. get(): This method will get an element of Vector stored at a particular index.
Syntax:
Vector.get(3);
Example:
Matrix without sorting 5 2 0 7 1 3 4 2 9 14 5 1 3 5 2 4 2 6 2 1 0 6 3 5 1 Matrix after sorting 1 2 0 7 1 3 2 2 9 14 5 1 3 5 2 4 2 6 4 1 0 6 3 5 5