Sunday, August 9, 2009

Desending Sort - Java Program

Hi friends, welcome back to Java Code Online. Today I will discuss the Java Program for sorting an array of numbers in descending order. It is similar to the previous Java program I discussed for ascending sort.

The strong point of this Java code is that, we make use of TreeSet Collection for sorting the array in reverse order. The Java code is provided below:-


import java.util.TreeSet;


public class SortingDescending {

@SuppressWarnings("unchecked")
public static void main(String[] args) {
int[] num = {3,5,9,2,1,0,45,23,67,93};
TreeSet ts = new TreeSet();

for(int i = 0; i < num.length; i++)
{
ts.add(num[i]);
}
System.out.println("The numbers of the array in descrending order are: "+ts.descendingSet());
}
}


I hope the Java Code provided was helpful to you all. For more info on Java, keep buzzing Java Code Online.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.