Java Program to Sort Vector Using Collections.sort() Method Last Updated : 11 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report java.util.Collections.sort() method is present in java.util.Collections class. It is used to sort the elements present in the specified list of Collection in ascending order. Syntax: Public void sort(Vector object); Parameters: Instance of the vector as an argument Illustration: Collection.sort() method Let us suppose that our list contains {"Geeks For Geeks", "Friends", "Dear", "Is", "Superb"} After using Collection.sort(), we obtain a sorted list as {"Dear", "Friends", "Geeks For Geeks", "Is", "Superb"}Create a vector instance.Add elements in the vector.Printing vector before function using the method to illustrate what the function is responsible for.Using Collection.sort() method.Print vector after sorting and it is seen sorting is ascending. Example 1: Java // Java Program to Sort Vector // using Collections.sort() Method // Importing Collection and Vector class import java.util.Collections; import java.util.Vector; public class GFG { // Main driver method public static void main(String args[]) { // Create a instance vector Vector<String> vec = new Vector<String>(); // Insert the values in vector vec.add("a"); vec.add("d"); vec.add("e"); vec.add("b"); vec.add("c"); // Display the vector System.out.println("original vector : " + vec); // Call sort() method Collections.sort(vec); // Display vector after replacing value System.out.println("\nsorted vector : " + vec); } } Outputoriginal vector : [a, d, e, b, c] sorted vector : [a, b, c, d, e] Example 2: Java // Java Program to Sort Vector // using Collections.sort() Method // Importing Collection and Vector class import java.util.Collections; import java.util.Vector; public class GFG { // Main driver method public static void main(String args[]) { // Create a instance vector Vector<String> vec = new Vector<String>(); // Insert the values in vector vec.add("4"); vec.add("2"); vec.add("7"); vec.add("3"); vec.add("2"); // Display the vector System.out.println("\noriginal vector : " + vec); // Call sort() method Collections.sort(vec); // Display vector after replacing value System.out.println("\nsorted vector : " + vec); } } Output original vector : [4, 2, 7, 3, 2] sorted vector : [2, 2, 3, 4, 7] Comment More infoAdvertise with us Next Article Java Program to Copy Elements of ArrayList to Vector M mukulsomukesh Follow Improve Article Tags : Java Java Programs Java-Collections Java-Vector Practice Tags : JavaJava-Collections Similar Reads Java Program to Sort LinkedList using Comparable In Java, LinkedList is a part of the collection framework provided in java.util package. LinkedList is a linear data structure where all the elements are unsorted in contiguous memory locations. The advantage of LinkedList is it is dynamic and easy to insert and delete any element. We can not access 5 min read Java Program to Copy Elements of ArrayList to Vector Vector implements List Interface, like ArrayList it also maintains insertion order but it is rarely used in the non-thread environment as it is synchronized, and due to which it gives a poor performance in adding, searching, deleting, and updating of its elements. To copy elements from one collectio 4 min read Sort Java Vector in Descending Order Using Comparator 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 the List interface. There are two types of Sorting t 3 min read How to Sort Vector Elements using Comparable Interface in Java? Vector is a child interface of collection. If we want to represent a group of the individual objects as a single entity where duplicates are allowed and insertion order must be preserved then we should go for vector. It is a resizable or growable array. It implements a Serializable, Cloneable, and R 5 min read Java Program to Sort Names in an Alphabetical Order For, sorting names in an Alphabetical order there are multiple ways to sort the array, like using inbuilt Arrays.sort() method or using normal sorting algorithms like the bubble sort, merge sort. Here let's use the bubble sort and inbuilt sort. Example: Input : Array[] = {"Sourabh", "Anoop, "Harsh", 3 min read Java Program to Sort ArrayList of Custom Objects By Property Here we are going to look at the approach of sorting an ArrayList of custom objects by using a property. Approach: 1. Create a getter function which returns the value stored in the class variable. 2. Create a list and use sort() function which takes the values of the list as arguments and compares t 2 min read Like