List reverse order java

next prev

Java Collections reverseOrder[] Method

The reverseOrder[] is a Java Collections class method which returns a comparator that imposes the reverse of the natural ordering on the objects. There is two different types of Java reverseOrder[] method which can be differentiated depending on its parameter. These are:

  1. Java Collections reverseOrder[] Method
  2. Java Collections reverseOrder[comp] Method

Java Collections reverseOrder[] Method

The reverseOrder[] method of Java Collections class is used to get the comparator that imposes the reverse of the natural ordering on a collection of objects which implement the Comparable interface.

Java Collections reverseOrder[comp] Method

The reverseOrder[] method of Java Collections class is used to get the comparator that imposes the reverse ordering of the specified comparator.

Syntax

Following is the declaration of reverseOrder[] method:

Parameter

ParameterDescriptionRequired/Optional
compIt is a comparator whose ordering is to be reversed by the returned comparator or null.Required

Returns

MethodReturns
reverseOrder[]It returns a comparator that imposes the reverse natural ordering on a collection of objects that implement the Comparable interface.
reverseOrder[Comparatorcomp]It returns a comparator that imposes the reverse ordering of the specified comparator.

Exceptions

NA

Compatibility Version

Java 1.5 and above

Example 1

Test it Now

Output:

List sorted in ReverseOrder: [90, 50, 10, -15, -20]

Example 2

Test it Now

Output:

List sorted in ReverseOrder: [Ruby, Python, Java, COBOL]

Example 3

Test it Now

Output:

[Ruby, Commit, Pratham, Jaya]

Example 4

Test it Now

Output:

List sorted in ReverseOrder: 120 50 -20 -80

Next TopicJava Collections Class


prev next


Video liên quan

Chủ Đề