Javatpoint Logo
Javatpoint Logo

Java Vector sort() Method

The sort() method of Java Vector class is used to sort the vector according to the order induced by the specified Comparator.

Syntax

Following is the declaration of a sort() method:

Parameter

Parameter Description Required/Optional
c It is the Comparator which is used to compare vector elements. Required

Return

This method has return type void so, it does not return anything.

Exceptions

NA

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

Components of the vector: [1, 5, 2, 4, 3]
Components of the vector after sorting: [1, 2, 3, 4, 5]

Example 2

Test it Now

Output:

The vector elements are: 
  White
  Green
  Black
  Orange
The vector elements after sort() method are: 
  Black
  Green
  Orange
  White

Next TopicJava Vector





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA