?
Solved

sorting

Posted on 2000-05-18
3
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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