Solved

sorting

Posted on 2000-05-18
3
203 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now