[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sorting

Posted on 2000-05-18
3
Medium Priority
?
212 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 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 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