Tuesday, July 28, 2009

Sorting Ascending - Java Program

Hi friends, welcome back to Java Code Online. This tutorial discusses the Java Code to sort the numbers in an Array in ascending order. This Java Code is helpful in getting a better idea of the Java fundamentals, and also provide the advantage of one of the most commonly used Java Collection named TreeSet.

The Java Code is given below:-

import java.util.TreeSet;


public class SortingAscending {

@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 ascending order are: "+ts);
}
}


For more information on Java, keep buzzing Java Code Online.

No comments:

Post a Comment

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