Solved

sorting

Posted on 2000-05-18
3
206 Views
Last Modified: 2010-04-01
I got problem with sorting an array in java. Can any one give a source code of sorting array in java or referring me to website that i can learn about sorting in java

thanks

0
Comment
Question by:H3R1
3 Comments
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2820192
in package java.util.Arrays you'll find
all support for sorting objects arrays,
look here a single example

"public static void sort(Object[] a)
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface. Furthermore, all elements in the array must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

Parameters:
a - the array to be sorted.
Throws:
ClassCastException - if the array contains elements that are not mutually comparable (for example, strings and integers).
See Also:
Comparable"
0
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 100 total points
ID: 2820285
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2821265
Even if you can use the Arrays class (it arrived in Java 2), it might be interesting for you to have a look at the Sorting Algorithms page if you care to learn more about sorting, see some applet demonstrations of various techniques, and/or download the implementations.
    http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html

Best regards,
Jim Cakalic
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question